<?php

namespace App\Http\Controllers\Admin;
header('Content-Type:text/html;charset=utf-8');


use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Route,URL,Auth;


class BigapiController extends Controller
{	
	//获取登录人的主地址
	public function getmap(request $request){
		$dengji = Auth::guard('admin')->user()->dengji;

		if ($dengji == 1) {

			 $json = array('city'=>'no');
			 $jcity = json_encode($json,true);
			 echo $jcity;
			 exit;

		}elseif($dengji == 2){
			$city = Auth::guard('admin')->user()->city;
			$nid['id'] = $city;
			$area = DB::table('area')->where($nid)->first();

			if ($area) {
				 $newarea = $area->name;
				 $json = array('city'=>$newarea);
				 $jcity = json_encode($json,true);
				 echo $jcity;
				 exit;
			}else{
				 $json = array('city'=>'no');
				 $jcity = json_encode($json,true);
				 echo $jcity;
				 exit;
			}


		}elseif($dengji == 3){

			$city = Auth::guard('admin')->user()->area;
			$nid['id'] = $city;
			$area = DB::table('area')->where($nid)->first();
			if ($area) {

				 $c['id'] = $area->cid;
				 $d = DB::table('area')->where($c)->first();
				 $newcity = $d->name;

				 $newarea = $area->name;
				 $json = array('city'=>$newcity,'big'=>$newarea);
				 $jcity = json_encode($json,true);
				 echo $jcity;
				 exit;
			}else{
				 $json = array('city'=>'no');
				 $jcity = json_encode($json,true);
				 echo $jcity;
				 exit;
			}



		}else{

			$city = Auth::guard('admin')->user()->org_id;
			$nid['id'] = $city;
			$area = DB::table('area')->where($nid)->first();
			if ($area) {
				 $newarea = $area->name;
				 $json = array('city'=>$newarea);
				 $jcity = json_encode($json,true);
				 echo $jcity;
				 exit;
			}else{
				 $json = array('city'=>'no');
				 $jcity = json_encode($json,true);
				 echo $jcity;
				 exit;
			}

		}
		
	

	}
	//单位数量统计
	public function getunit(request $request){
		// 根据登录等级获取数量
		$dengji = Auth::guard('admin')->user()->dengji;
		$name1 = $request->name1;
		$name2 = $request->name2;



		$id = $request->id;
		$nid['id'] = $request->id;
		$area = DB::table('area')->where($nid)->first();

		$where = '';
		if(Auth::guard('admin')->user()->dengji == 4){
			$user_id = Auth::guard('admin')->user()->id;
			$where .= "and units.minjing = $user_id ";
		}
		if($request->name){
			$where .= "and units.name LIKE '%$request->name%' ";
		}
		if($request->type != null){
			$where .= "and units.type = $request->type ";
		}
		if($request->xingzhi != null){
			$where .= "and units.xingzhi = $request->xingzhi ";
		}
		if($request->is_del != null){
			$where .= "and units.is_del = $request->is_del ";
		}
		if($request->jibie != null){
			$where .= "and units.is_imp = $request->jibie ";
		}


		if ($id || $name2) {
	
		if ($id) {

			 if ($area->dengji == 1) {
			 	$city = DB::select("SELECT area.name,COUNT(*) as value FROM units LEFT JOIN area on area.id = units.area WHERE area.cid = ? $where GROUP BY area.name",[$id]);

			 }

			 if ($area->dengji == 2) {
                $city = DB::select("SELECT area.name,COUNT(*) as value FROM units LEFT JOIN area on area.id = units.org_id WHERE area.cid = ? $where GROUP BY area.name",[$id]);
             }

              if ($area->dengji == 3) {
                $city = DB::select("SELECT area.name,COUNT(*) as value FROM units LEFT JOIN area on area.id = units.org_id WHERE area.id = ? $where GROUP BY area.name",[$id]);
             }
        }





		if ($name2) {


			if ($name1 == '湖北省') {
				$area = db::table('area')->where('name',$name2)->first();
				if ($area->dengji == 1)
				{
					$aid = $area->id;
					$city = DB::select("SELECT area.name,COUNT(*) as value FROM units LEFT JOIN area on area.id = units.area WHERE area.cid = ? $where GROUP BY area.name",[$aid]);
				}
			}else{
				
				$b = db::table('area')->where('name',$name1)->first();
				$c['cid'] = $b->id;
				$c['name'] = $name2;
				$d = db::table('area')->where($c)->first();
				if ($d) {
					$aid = $d->id;
					$city = DB::select("SELECT area.name,COUNT(*) as value FROM units LEFT JOIN area on area.id = units.org_id WHERE area.cid = ? $where GROUP BY area.name",[$aid]);
				}
 			}
 		}

		}else{

			if ($dengji == 1) {
			//获取全省下的市下的单位数
			 $city = DB::select("SELECT area.name,COUNT(*) as value FROM units LEFT JOIN area on area.id = units.city WHERE area.cid = 0 $where GROUP BY area.name");

			
			}

			if ($dengji == 2) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT area.name,COUNT(*) as value FROM units LEFT JOIN area on area.id = units.area WHERE area.id IN ($areaid) $where GROUP BY area.name");
				
			}

			if ($dengji == 3) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT area.name,COUNT(*) as value FROM units LEFT JOIN area on area.id = units.org_id WHERE area.id IN ($areaid) $where GROUP BY area.name");
				
			}

			if ($dengji == 4) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT area.name,COUNT(*) as value FROM units LEFT JOIN area on area.id = units.org_id WHERE area.id IN ($areaid) $where GROUP BY area.name");
			
			}

		}

		


		 	 $json = array('city'=>$city);
			 $jcity = json_encode($json,true);
			 echo $jcity;
			 exit;


	}

	public function getpolice(request $request){
			// 根据登录等级获取数量
		$dengji = Auth::guard('admin')->user()->dengji;
		$name1 = $request->name1;
		$name2 = $request->name2;
		$id = $request->id;
		$nid['id'] = $request->id;
		$area = DB::table('area')->where($nid)->first();

		$where = '';
		// if(Auth::guard('admin')->user()->dengji == 4){
		// 	$user_id = Auth::guard('admin')->user()->id;
		// 	$where .= "and units.minjing = $user_id ";
		// }
		// if($request->name){
		// 	$where .= "and units.name LIKE '%$request->name%' ";
		// }
		// if($request->type != null){
		// 	$where .= "and units.type = $request->type ";
		// }
		// if($request->xingzhi != null){
		// 	$where .= "and units.xingzhi = $request->xingzhi ";
		// }
		// if($request->is_del != null){
		// 	$where .= "and units.is_del = $request->is_del ";
		// }
		// if($request->jibie != null){
		// 	$where .= "and units.is_imp = $request->jibie ";
		// }
		if ($id || $name2) {
		// if ($id) {

		// 	 if ($area->dengji == 1) {
		// 	 	$city = DB::select("SELECT area.name,COUNT(*) as value FROM units LEFT JOIN area on area.id = units.area WHERE area.cid = $id $where GROUP BY area.name");

		// 	 }

		// 	 if ($area->dengji == 2) {
  //               $city = DB::select("SELECT area.name,COUNT(*) as value FROM units LEFT JOIN area on area.id = units.org_id WHERE area.cid = $id $where GROUP BY area.name");
  //            }

  //             if ($area->dengji == 3) {
  //               $city = DB::select("SELECT area.name,COUNT(*) as value FROM units LEFT JOIN area on area.id = units.org_id WHERE area.id = $id $where GROUP BY area.name");
  //            }
  //       }
		if ($name2) {

			if ($name1 == '湖北省') {
				$area = db::table('area')->where('name',$name2)->first();
				if ($area->dengji == 1)
				{
					$aid = $area->id;
					$city = DB::select("SELECT area.name,COUNT(*) as value FROM admin_users LEFT JOIN area on area.id = admin_users.area WHERE area.cid = ? $where GROUP BY area.name",[$aid]);
				}
			}else{
				$b = db::table('area')->where('name',$name1)->first();
				$c['cid'] = $b->id;
				$c['name'] = $name2;
				$d = db::table('area')->where($c)->first();
				if ($d) {
					$aid = $d->id;
					$city = DB::select("SELECT area.name,COUNT(*) as value FROM admin_users LEFT JOIN area on area.id = admin_users.org_id WHERE area.cid = ? $where GROUP BY area.name",[$aid]);
				}
 			}
 		}
		}else{
			if ($dengji == 1) {
			//获取全省下的市下的单位数
			 $city = DB::select("SELECT area.name,COUNT(*) as value FROM admin_users LEFT JOIN area on area.id = admin_users.city WHERE admin_users.role_id = 15 GROUP BY area.name");
			
			}
			if ($dengji == 2) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select("SELECT area.name,COUNT(*) as value FROM admin_users LEFT JOIN area on area.id = admin_users.area WHERE admin_users.role_id = 15 and area.id IN ($areaid) GROUP BY area.name");
			}

			if ($dengji == 3) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select("SELECT area.name,COUNT(*) as value FROM admin_users LEFT JOIN area on area.id = admin_users.area WHERE admin_users.org_id = 15 and area.id IN ($areaid) GROUP BY area.name");				
			}

			if ($dengji == 4) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select("SELECT area.name,COUNT(*) as value FROM admin_users LEFT JOIN area on area.id = admin_users.area WHERE admin_users.org_id = 15 and area.id IN ($areaid) GROUP BY area.name");
			
			}

		}
		 	 $json = array('city'=>$city);
			 $jcity = json_encode($json,true);
			 echo $jcity;
			 exit;
	}

	public function policeph(request $request){

		// 根据登录等级获取数量
		$dengji = Auth::guard('admin')->user()->dengji;
		$name1 = $request->name1;
		$name2 = $request->name2;
		$id = $request->id;
		$nid['id'] = $request->id;
		$area = DB::table('area')->where($nid)->first();

		$where = '';
		// if(Auth::guard('admin')->user()->dengji == 4){
		// 	$user_id = Auth::guard('admin')->user()->id;
		// 	$where .= "and units.minjing = $user_id ";
		// }
		// if($request->name){
		// 	$where .= "and units.name LIKE '%$request->name%' ";
		// }
		// if($request->type != null){
		// 	$where .= "and units.type = $request->type ";
		// }
		// if($request->xingzhi != null){
		// 	$where .= "and units.xingzhi = $request->xingzhi ";
		// }
		// if($request->is_del != null){
		// 	$where .= "and units.is_del = $request->is_del ";
		// }
		// if($request->jibie != null){
		// 	$where .= "and units.is_imp = $request->jibie ";
		// }

		if ($id || $name2) {
		// if ($id) {

		// 	 if ($area->dengji == 1) {
		// 	 	$city = DB::select("SELECT area.name,COUNT(*) as value FROM units LEFT JOIN area on area.id = units.area WHERE area.cid = $id $where GROUP BY area.name");

		// 	 }

		// 	 if ($area->dengji == 2) {
  //               $city = DB::select("SELECT area.name,COUNT(*) as value FROM units LEFT JOIN area on area.id = units.org_id WHERE area.cid = $id $where GROUP BY area.name");
  //            }

  //             if ($area->dengji == 3) {
  //               $city = DB::select("SELECT area.name,COUNT(*) as value FROM units LEFT JOIN area on area.id = units.org_id WHERE area.id = $id $where GROUP BY area.name");
  //            }
  //       }
		if ($name2) {
			if ($name1 == '湖北省') {
				$area = db::table('area')->where('name',$name2)->first();
				if ($area->dengji == 1)
				{
					$aid = $area->id;
				
					//$city = DB::select("SELECT area.name,COUNT(*) as value FROM admin_users LEFT JOIN area on area.id = admin_users.area WHERE area.cid = $aid $where GROUP BY area.name");

					//删除
					DB::table('mapmjph')->delete();


					//检查
					 $jc = DB::select("SELECT  area.name as areaname,jc.user_id ,count(1)as count FROM `admin_users` as us  INNER JOIN jiancha as jc ON jc.user_id = us.id INNER JOIN area on area.id = us.area WHERE us.role_id = 15 and area.cid = ? GROUP BY area.name,jc.user_id ORDER BY count DESC",[$aid]);

					 foreach ($jc as $key => $value) {
							$ry['user_id'] = $value->user_id;
							$ry['newcount'] = $value->count;
							$ry['areaname'] = $value->areaname;
							DB::table('mapmjph')->insert($ry);
						}

					//人员审核
					$rysh = DB::select("SELECT  area.name as areaname,rysh.police_id,count(1)as count FROM `admin_users` as us INNER JOIN rysh ON rysh.police_id = us.id INNER JOIN area on area.id = us.area WHERE us.role_id = 15 AND rysh.police_cl = 1 and area.cid = ? GROUP BY area.name,rysh.police_id ORDER BY count DESC",[$aid]);

					foreach ($rysh as $key => $value) {
						$j['user_id'] = $value->police_id;
						$jq['newcount'] = $value->count;
						$jq['areaname'] = $value->areaname;
						$fj = DB::table('mapmjph')->where($j)->first();
						if ($fj) {
							DB::table('mapmjph')->where($j)->increment('newcount',$value->count);
							}else{
							$jq['user_id'] = $value->police_id;
							DB::table('mapmjph')->insert($jq);
						}
					}

					//警情上报
					$jqsb =  DB::select("SELECT  area.name as areaname,jqsb.police_id,count(1)as count FROM `admin_users` as us INNER JOIN jqsb ON jqsb.police_id = us.id INNER JOIN area on area.id = us.area WHERE us.role_id = 15 AND jqsb.police_cl = 1 and area.cid = ? GROUP BY area.name,jqsb.police_id ORDER BY count DESC",[$aid]);


					foreach ($jqsb as $key => $value) {
							$j['user_id'] = $value->police_id;
							$jq['newcount'] = $value->count;
							$jq['areaname'] = $value->areaname;
							$fj = DB::table('mapmjph')->where($j)->first();
							if ($fj) {
								DB::table('mapmjph')->where($j)->increment('newcount',$value->count);
								}else{
								$jq['user_id'] = $value->police_id;
								DB::table('mapmjph')->insert($jq);
							}
						}

					//意见反馈
						$yjfk =  DB::select("SELECT  area.name as areaname,yjfk.police_id,count(1)as count FROM `admin_users` as us INNER JOIN yjfk ON yjfk.police_id = us.id INNER JOIN area on area.id = us.area WHERE us.role_id = 15 AND yjfk.police_cl = 1 and area.cid = ? GROUP BY area.name,yjfk.police_id ORDER BY count DESC",[$aid]);
						foreach ($yjfk as $key => $value) {
									$j['user_id'] = $value->police_id;
									$jq['newcount'] = $value->count;
									$jq['areaname'] = $value->areaname;
									$fj = DB::table('mapmjph')->where($j)->first();
									if ($fj) {
										DB::table('mapmjph')->where($j)->increment('newcount',$value->count);
									}else{
										$jq['user_id'] = $value->police_id;
										DB::table('mapmjph')->insert($jq);
									}
						}


					$city = DB::select("SELECT u.count,u.user_id,u.name,(CASE WHEN @rowtotal = u.count THEN @rownum WHEN @rowtotal := u.count THEN @rownum :=@rownum + 1 WHEN @rowtotal = 0 THEN @rownum :=@rownum + 1 END) as rank FROM (SELECT  mapmjph.user_id, us.name ,mapmjph.newcount as count FROM `mapmjph`  LEFT JOIN admin_users as us ON us.id = mapmjph.user_id  ORDER BY count DESC  LIMIT 10 ) AS u,(SELECT @rownum := 0 ,@rowtotal := NULL) r");		




				}
			}else{
				$b = db::table('area')->where('name',$name1)->first();
				$c['cid'] = $b->id;
				$c['name'] = $name2;
				$d = db::table('area')->where($c)->first();
				if ($d) {
					$aid = $d->id;
					//$city = DB::select("SELECT area.name,COUNT(*) as value FROM admin_users LEFT JOIN area on area.id = admin_users.org_id WHERE area.cid = $aid $where GROUP BY area.name");

						//删除
					DB::table('mapmjph')->delete();


					//检查
					 $jc = DB::select("SELECT  area.name as areaname,jc.user_id ,count(1)as count FROM `admin_users` as us  INNER JOIN jiancha as jc ON jc.user_id = us.id INNER JOIN area on area.id = us.org_id WHERE us.role_id = 15 and area.cid = ? GROUP BY area.name,jc.user_id ORDER BY count DESC",[$aid]);

					 foreach ($jc as $key => $value) {
							$ry['user_id'] = $value->user_id;
							$ry['newcount'] = $value->count;
							$ry['areaname'] = $value->areaname;
							DB::table('mapmjph')->insert($ry);
						}

					//人员审核
					$rysh = DB::select("SELECT  area.name as areaname,rysh.police_id,count(1)as count FROM `admin_users` as us INNER JOIN rysh ON rysh.police_id = us.id INNER JOIN area on area.id = us.org_id WHERE us.role_id = 15 AND rysh.police_cl = 1 and area.cid = ? GROUP BY area.name,rysh.police_id ORDER BY count DESC",[$aid]);

					foreach ($rysh as $key => $value) {
						$j['user_id'] = $value->police_id;
						$jq['newcount'] = $value->count;
						$jq['areaname'] = $value->areaname;
						$fj = DB::table('mapmjph')->where($j)->first();
						if ($fj) {
							DB::table('mapmjph')->where($j)->increment('newcount',$value->count);
							}else{
							$jq['user_id'] = $value->police_id;
							DB::table('mapmjph')->insert($jq);
						}
					}

					//警情上报
					$jqsb =  DB::select("SELECT  area.name as areaname,jqsb.police_id,count(1)as count FROM `admin_users` as us INNER JOIN jqsb ON jqsb.police_id = us.id INNER JOIN area on area.id = us.org_id WHERE us.role_id = 15 AND jqsb.police_cl = 1 and area.cid = ? GROUP BY area.name,jqsb.police_id ORDER BY count DESC",[$aid]);


					foreach ($jqsb as $key => $value) {
							$j['user_id'] = $value->police_id;
							$jq['newcount'] = $value->count;
							$jq['areaname'] = $value->areaname;
							$fj = DB::table('mapmjph')->where($j)->first();
							if ($fj) {
								DB::table('mapmjph')->where($j)->increment('newcount',$value->count);
								}else{
								$jq['user_id'] = $value->police_id;
								DB::table('mapmjph')->insert($jq);
							}
						}

					//意见反馈
						$yjfk =  DB::select("SELECT  area.name as areaname,yjfk.police_id,count(1)as count FROM `admin_users` as us INNER JOIN yjfk ON yjfk.police_id = us.id INNER JOIN area on area.id = us.org_id WHERE us.role_id = 15 AND yjfk.police_cl = 1 and area.cid = ? GROUP BY area.name,yjfk.police_id ORDER BY count DESC",[$aid]);
						foreach ($yjfk as $key => $value) {
									$j['user_id'] = $value->police_id;
									$jq['newcount'] = $value->count;
									$jq['areaname'] = $value->areaname;
									$fj = DB::table('mapmjph')->where($j)->first();
									if ($fj) {
										DB::table('mapmjph')->where($j)->increment('newcount',$value->count);
									}else{
										$jq['user_id'] = $value->police_id;
										DB::table('mapmjph')->insert($jq);
									}
						}


					$city = DB::select("SELECT u.count,u.user_id,u.name,(CASE WHEN @rowtotal = u.count THEN @rownum WHEN @rowtotal := u.count THEN @rownum :=@rownum + 1 WHEN @rowtotal = 0 THEN @rownum :=@rownum + 1 END) as rank FROM (SELECT  mapmjph.user_id, us.name ,mapmjph.newcount as count FROM `mapmjph`  LEFT JOIN admin_users as us ON us.id = mapmjph.user_id  ORDER BY count DESC  LIMIT 10 ) AS u,(SELECT @rownum := 0 ,@rowtotal := NULL) r");		



				}
 			}
 		}
		}else{
			if ($dengji == 1) {
			//获取全省下的市下的单位数
			 // $city = DB::select("SELECT area.name,COUNT(*) as value FROM admin_users LEFT JOIN area on area.id = admin_users.city WHERE admin_users.role_id = 15 GROUP BY area.name");

			//删除
			DB::table('mapmjph')->delete();


			//检查
			 $jc = DB::select("SELECT  area.name as areaname,jc.user_id ,count(1)as count FROM `admin_users` as us  INNER JOIN jiancha as jc ON jc.user_id = us.id INNER JOIN area on area.id = us.city WHERE us.role_id = 15  GROUP BY area.name,jc.user_id ORDER BY count DESC");

			 foreach ($jc as $key => $value) {
					$ry['user_id'] = $value->user_id;
					$ry['newcount'] = $value->count;
					$ry['areaname'] = $value->areaname;
					DB::table('mapmjph')->insert($ry);
				}

			//人员审核
			$rysh = DB::select("SELECT  area.name as areaname,rysh.police_id,count(1)as count FROM `admin_users` as us INNER JOIN rysh ON rysh.police_id = us.id INNER JOIN area on area.id = us.city WHERE us.role_id = 15 AND rysh.police_cl = 1 GROUP BY area.name,rysh.police_id ORDER BY count DESC");

			foreach ($rysh as $key => $value) {
				$j['user_id'] = $value->police_id;
				$jq['newcount'] = $value->count;
				$jq['areaname'] = $value->areaname;
				$fj = DB::table('mapmjph')->where($j)->first();
				if ($fj) {
					DB::table('mapmjph')->where($j)->increment('newcount',$value->count);
					}else{
					$jq['user_id'] = $value->police_id;
					DB::table('mapmjph')->insert($jq);
				}
			}

			//警情上报
			$jqsb =  DB::select("SELECT  area.name as areaname,jqsb.police_id,count(1)as count FROM `admin_users` as us INNER JOIN jqsb ON jqsb.police_id = us.id INNER JOIN area on area.id = us.city WHERE us.role_id = 15 AND jqsb.police_cl = 1 GROUP BY area.name,jqsb.police_id ORDER BY count DESC");


			foreach ($jqsb as $key => $value) {
					$j['user_id'] = $value->police_id;
					$jq['newcount'] = $value->count;
					$jq['areaname'] = $value->areaname;
					$fj = DB::table('mapmjph')->where($j)->first();
					if ($fj) {
						DB::table('mapmjph')->where($j)->increment('newcount',$value->count);
						}else{
						$jq['user_id'] = $value->police_id;
						DB::table('mapmjph')->insert($jq);
					}
				}

			//意见反馈
				$yjfk =  DB::select("SELECT  area.name as areaname,yjfk.police_id,count(1)as count FROM `admin_users` as us INNER JOIN yjfk ON yjfk.police_id = us.id INNER JOIN area on area.id = us.city WHERE us.role_id = 15 AND yjfk.police_cl = 1 GROUP BY area.name,yjfk.police_id ORDER BY count DESC");
				foreach ($yjfk as $key => $value) {
							$j['user_id'] = $value->police_id;
							$jq['newcount'] = $value->count;
							$jq['areaname'] = $value->areaname;
							$fj = DB::table('mapmjph')->where($j)->first();
							if ($fj) {
								DB::table('mapmjph')->where($j)->increment('newcount',$value->count);
							}else{
								$jq['user_id'] = $value->police_id;
								DB::table('mapmjph')->insert($jq);
							}
				}

				$city = DB::select("SELECT u.count,u.user_id,u.name,(CASE WHEN @rowtotal = u.count THEN @rownum WHEN @rowtotal := u.count THEN @rownum :=@rownum + 1 WHEN @rowtotal = 0 THEN @rownum :=@rownum + 1 END) as rank FROM (SELECT  mapmjph.user_id, us.name ,mapmjph.newcount as count FROM `mapmjph`  LEFT JOIN admin_users as us ON us.id = mapmjph.user_id  ORDER BY count DESC  LIMIT 10 ) AS u,(SELECT @rownum := 0 ,@rowtotal := NULL) r");			
			}



			if ($dengji == 2) {
				$areaid = Auth::guard('admin')->user()->area_id;
				//$city = DB::select("SELECT area.name,COUNT(*) as value FROM admin_users LEFT JOIN area on area.id = admin_users.area WHERE admin_users.role_id = 15 and area.id IN ($areaid) GROUP BY area.name");

					//删除
				DB::table('mapmjph')->delete();


				//检查
				 $jc = DB::select("SELECT  area.name as areaname,jc.user_id ,count(1)as count FROM `admin_users` as us  INNER JOIN jiancha as jc ON jc.user_id = us.id INNER JOIN area on area.id = us.area WHERE us.role_id = 15 and area.id IN ($areaid) GROUP BY area.name,jc.user_id ORDER BY count DESC");

				 foreach ($jc as $key => $value) {
						$ry['user_id'] = $value->user_id;
						$ry['newcount'] = $value->count;
						$ry['areaname'] = $value->areaname;
						DB::table('mapmjph')->insert($ry);
					}

				//人员审核
				$rysh = DB::select("SELECT  area.name as areaname,rysh.police_id,count(1)as count FROM `admin_users` as us INNER JOIN rysh ON rysh.police_id = us.id INNER JOIN area on area.id = us.area WHERE us.role_id = 15 AND rysh.police_cl = 1 and area.id IN ($areaid) GROUP BY area.name,rysh.police_id ORDER BY count DESC");

				foreach ($rysh as $key => $value) {
					$j['user_id'] = $value->police_id;
					$jq['newcount'] = $value->count;
					$jq['areaname'] = $value->areaname;
					$fj = DB::table('mapmjph')->where($j)->first();
					if ($fj) {
						DB::table('mapmjph')->where($j)->increment('newcount',$value->count);
						}else{
						$jq['user_id'] = $value->police_id;
						DB::table('mapmjph')->insert($jq);
					}
				}

				//警情上报
				$jqsb =  DB::select("SELECT  area.name as areaname,jqsb.police_id,count(1)as count FROM `admin_users` as us INNER JOIN jqsb ON jqsb.police_id = us.id INNER JOIN area on area.id = us.area WHERE us.role_id = 15 AND jqsb.police_cl = 1 and area.id IN ($areaid) GROUP BY area.name,jqsb.police_id ORDER BY count DESC");


				foreach ($jqsb as $key => $value) {
						$j['user_id'] = $value->police_id;
						$jq['newcount'] = $value->count;
						$jq['areaname'] = $value->areaname;
						$fj = DB::table('mapmjph')->where($j)->first();
						if ($fj) {
							DB::table('mapmjph')->where($j)->increment('newcount',$value->count);
							}else{
							$jq['user_id'] = $value->police_id;
							DB::table('mapmjph')->insert($jq);
						}
					}

				//意见反馈
					$yjfk =  DB::select("SELECT  area.name as areaname,yjfk.police_id,count(1)as count FROM `admin_users` as us INNER JOIN yjfk ON yjfk.police_id = us.id INNER JOIN area on area.id = us.area WHERE us.role_id = 15 AND yjfk.police_cl = 1 and area.id IN ($areaid) GROUP BY area.name,yjfk.police_id ORDER BY count DESC");
					foreach ($yjfk as $key => $value) {
								$j['user_id'] = $value->police_id;
								$jq['newcount'] = $value->count;
								$jq['areaname'] = $value->areaname;
								$fj = DB::table('mapmjph')->where($j)->first();
								if ($fj) {
									DB::table('mapmjph')->where($j)->increment('newcount',$value->count);
								}else{
									$jq['user_id'] = $value->police_id;
									DB::table('mapmjph')->insert($jq);
								}
					}


				$city = DB::select("SELECT u.count,u.user_id,u.name,(CASE WHEN @rowtotal = u.count THEN @rownum WHEN @rowtotal := u.count THEN @rownum :=@rownum + 1 WHEN @rowtotal = 0 THEN @rownum :=@rownum + 1 END) as rank FROM (SELECT  mapmjph.user_id, us.name ,mapmjph.newcount as count FROM `mapmjph`  LEFT JOIN admin_users as us ON us.id = mapmjph.user_id  ORDER BY count DESC  LIMIT 10 ) AS u,(SELECT @rownum := 0 ,@rowtotal := NULL) r");		



			}

			if ($dengji == 3) {
				$areaid = Auth::guard('admin')->user()->area_id;
				//$city = DB::select("SELECT area.name,COUNT(*) as value FROM admin_users LEFT JOIN area on area.id = admin_users.area WHERE admin_users.org_id = 15 and area.id IN ($areaid) GROUP BY area.name");	

									//删除
				DB::table('mapmjph')->delete();


				//检查
				 $jc = DB::select("SELECT  area.name as areaname,jc.user_id ,count(1)as count FROM `admin_users` as us  INNER JOIN jiancha as jc ON jc.user_id = us.id INNER JOIN area on area.id = us.area WHERE us.role_id = 15 and area.id IN ($areaid) GROUP BY area.name,jc.user_id ORDER BY count DESC");

				 foreach ($jc as $key => $value) {
						$ry['user_id'] = $value->user_id;
						$ry['newcount'] = $value->count;
						$ry['areaname'] = $value->areaname;
						DB::table('mapmjph')->insert($ry);
					}

				//人员审核
				$rysh = DB::select("SELECT  area.name as areaname,rysh.police_id,count(1)as count FROM `admin_users` as us INNER JOIN rysh ON rysh.police_id = us.id INNER JOIN area on area.id = us.area WHERE us.role_id = 15 AND rysh.police_cl = 1 and area.id IN ($areaid) GROUP BY area.name,rysh.police_id ORDER BY count DESC");

				foreach ($rysh as $key => $value) {
					$j['user_id'] = $value->police_id;
					$jq['newcount'] = $value->count;
					$jq['areaname'] = $value->areaname;
					$fj = DB::table('mapmjph')->where($j)->first();
					if ($fj) {
						DB::table('mapmjph')->where($j)->increment('newcount',$value->count);
						}else{
						$jq['user_id'] = $value->police_id;
						DB::table('mapmjph')->insert($jq);
					}
				}

				//警情上报
				$jqsb =  DB::select("SELECT  area.name as areaname,jqsb.police_id,count(1)as count FROM `admin_users` as us INNER JOIN jqsb ON jqsb.police_id = us.id INNER JOIN area on area.id = us.area WHERE us.role_id = 15 AND jqsb.police_cl = 1 and area.id IN ($areaid) GROUP BY area.name,jqsb.police_id ORDER BY count DESC");


				foreach ($jqsb as $key => $value) {
						$j['user_id'] = $value->police_id;
						$jq['newcount'] = $value->count;
						$jq['areaname'] = $value->areaname;
						$fj = DB::table('mapmjph')->where($j)->first();
						if ($fj) {
							DB::table('mapmjph')->where($j)->increment('newcount',$value->count);
							}else{
							$jq['user_id'] = $value->police_id;
							DB::table('mapmjph')->insert($jq);
						}
					}

				//意见反馈
					$yjfk =  DB::select("SELECT  area.name as areaname,yjfk.police_id,count(1)as count FROM `admin_users` as us INNER JOIN yjfk ON yjfk.police_id = us.id INNER JOIN area on area.id = us.area WHERE us.role_id = 15 AND yjfk.police_cl = 1 and area.id IN ($areaid) GROUP BY area.name,yjfk.police_id ORDER BY count DESC");
					foreach ($yjfk as $key => $value) {
								$j['user_id'] = $value->police_id;
								$jq['newcount'] = $value->count;
								$jq['areaname'] = $value->areaname;
								$fj = DB::table('mapmjph')->where($j)->first();
								if ($fj) {
									DB::table('mapmjph')->where($j)->increment('newcount',$value->count);
								}else{
									$jq['user_id'] = $value->police_id;
									DB::table('mapmjph')->insert($jq);
								}
					}


				$city = DB::select("SELECT u.count,u.user_id,u.name,(CASE WHEN @rowtotal = u.count THEN @rownum WHEN @rowtotal := u.count THEN @rownum :=@rownum + 1 WHEN @rowtotal = 0 THEN @rownum :=@rownum + 1 END) as rank FROM (SELECT  mapmjph.user_id, us.name ,mapmjph.newcount as count FROM `mapmjph`  LEFT JOIN admin_users as us ON us.id = mapmjph.user_id  ORDER BY count DESC  LIMIT 10 ) AS u,(SELECT @rownum := 0 ,@rowtotal := NULL) r");		


			
			}


			if ($dengji == 4) {
				$areaid = Auth::guard('admin')->user()->area_id;
				//$city = DB::select("SELECT area.name,COUNT(*) as value FROM admin_users LEFT JOIN area on area.id = admin_users.area WHERE admin_users.org_id = 15 and area.id IN ($areaid) GROUP BY area.name");										//删除
				DB::table('mapmjph')->delete();


				//检查
				 $jc = DB::select("SELECT  area.name as areaname,jc.user_id ,count(1)as count FROM `admin_users` as us  INNER JOIN jiancha as jc ON jc.user_id = us.id INNER JOIN area on area.id = us.area WHERE us.role_id = 15 and area.id IN ($areaid) GROUP BY area.name,jc.user_id ORDER BY count DESC");

				 foreach ($jc as $key => $value) {
						$ry['user_id'] = $value->user_id;
						$ry['newcount'] = $value->count;
						$ry['areaname'] = $value->areaname;
						DB::table('mapmjph')->insert($ry);
					}

				//人员审核
				$rysh = DB::select("SELECT  area.name as areaname,rysh.police_id,count(1)as count FROM `admin_users` as us INNER JOIN rysh ON rysh.police_id = us.id INNER JOIN area on area.id = us.area WHERE us.role_id = 15 AND rysh.police_cl = 1 and area.id IN ($areaid) GROUP BY area.name,rysh.police_id ORDER BY count DESC");

				foreach ($rysh as $key => $value) {
					$j['user_id'] = $value->police_id;
					$jq['newcount'] = $value->count;
					$jq['areaname'] = $value->areaname;
					$fj = DB::table('mapmjph')->where($j)->first();
					if ($fj) {
						DB::table('mapmjph')->where($j)->increment('newcount',$value->count);
						}else{
						$jq['user_id'] = $value->police_id;
						DB::table('mapmjph')->insert($jq);
					}
				}

				//警情上报
				$jqsb =  DB::select("SELECT  area.name as areaname,jqsb.police_id,count(1)as count FROM `admin_users` as us INNER JOIN jqsb ON jqsb.police_id = us.id INNER JOIN area on area.id = us.area WHERE us.role_id = 15 AND jqsb.police_cl = 1 and area.id IN ($areaid) GROUP BY area.name,jqsb.police_id ORDER BY count DESC");


				foreach ($jqsb as $key => $value) {
						$j['user_id'] = $value->police_id;
						$jq['newcount'] = $value->count;
						$jq['areaname'] = $value->areaname;
						$fj = DB::table('mapmjph')->where($j)->first();
						if ($fj) {
							DB::table('mapmjph')->where($j)->increment('newcount',$value->count);
							}else{
							$jq['user_id'] = $value->police_id;
							DB::table('mapmjph')->insert($jq);
						}
					}

				//意见反馈
					$yjfk =  DB::select("SELECT  area.name as areaname,yjfk.police_id,count(1)as count FROM `admin_users` as us INNER JOIN yjfk ON yjfk.police_id = us.id INNER JOIN area on area.id = us.area WHERE us.role_id = 15 AND yjfk.police_cl = 1 and area.id IN ($areaid) GROUP BY area.name,yjfk.police_id ORDER BY count DESC");
					foreach ($yjfk as $key => $value) {
								$j['user_id'] = $value->police_id;
								$jq['newcount'] = $value->count;
								$jq['areaname'] = $value->areaname;
								$fj = DB::table('mapmjph')->where($j)->first();
								if ($fj) {
									DB::table('mapmjph')->where($j)->increment('newcount',$value->count);
								}else{
									$jq['user_id'] = $value->police_id;
									DB::table('mapmjph')->insert($jq);
								}
					}


				$city = DB::select("SELECT u.count,u.user_id,u.name,(CASE WHEN @rowtotal = u.count THEN @rownum WHEN @rowtotal := u.count THEN @rownum :=@rownum + 1 WHEN @rowtotal = 0 THEN @rownum :=@rownum + 1 END) as rank FROM (SELECT  mapmjph.user_id, us.name ,mapmjph.newcount as count FROM `mapmjph`  LEFT JOIN admin_users as us ON us.id = mapmjph.user_id  ORDER BY count DESC  LIMIT 10 ) AS u,(SELECT @rownum := 0 ,@rowtotal := NULL) r");		

			}

		}

	 	 $json = array('city'=>$city);
		 $jcity = json_encode($json,true);
		 echo $jcity;
		 exit;
	}
	

	public function policexq(request $request){
		$id = $request->id;

		if ($id) {

			$mar['id'] = $id;
			//个人信息
			$re['user'] =  DB::table('admin_users')->where($mar)->select('name','phone','sex','city','area','org_id')->first();

			//性别
			if ($re['user']->sex == 1) {
				$re['sex'] = '男';
			}else{
				$re['sex'] = '女';
			}

			//地区
			if ($re['user']->city) {
				$area['id'] = $re['user']->city;
				$re['city'] = DB::table('area')->where($area)->select('name')->first();
			}

			if ($re['user']->area) {
				$area['id'] = $re['user']->area;
				$re['area'] = DB::table('area')->where($area)->select('name')->first();
			}

			if ($re['user']->org_id) {
				$area['id'] = $re['user']->org_id;
				$re['org'] = DB::table('area')->where($area)->select('name')->first();
			}


			//警情概况
			$nojq['police_id'] = $id;
			$nojq['police_cl'] = 0;
			$re['nojq'] =   DB::table('jqsb')->where($nojq)->count();


			$yejq['police_id'] = $id;
			$yejq['police_cl'] = 1;
			$re['yejq'] =   DB::table('jqsb')->where($yejq)->count();


			//人员核查
			$nory['police_id'] = $id;
			$nory['police_cl'] = 0;
			$re['nory'] =   DB::table('rysh')->where($nory)->count();


			$yery['police_id'] = $id;
			$yery['police_cl'] = 1;
			$re['yery'] =   DB::table('rysh')->where($yery)->count();


			//线索举报
			$noxs['police_id'] = $id;
			$noxs['police_cl'] = 0;
			$re['noxs'] =   DB::table('xiansuo')->where($noxs)->count();


			$yexs['police_id'] = $id;
			$yexs['police_cl'] = 1;
			$re['yexs'] =   DB::table('xiansuo')->where($yexs)->count();

			//企业检查
			$qyjc['user_id'] = $id;
			$re['qyjc'] = DB::table('jiancha')->where($qyjc)->count();
			


		}
		 $json = array('re'=>$re);
		 $jcity = json_encode($json,true);
		 echo $jcity;
		 exit;




	}







	//单位级别统计
	public function getdwjib(request $request){
			// 根据登录等级获取数量
			$dengji = Auth::guard('admin')->user()->dengji;
			$name1 = $request->name1;
			$name2 = $request->name2;

			$id = $request->id;
			$nid['id'] = $request->id;
			$area = DB::table('area')->where($nid)->first();

		$where = '';
		if(Auth::guard('admin')->user()->dengji == 4){
			$user_id = Auth::guard('admin')->user()->id;
			$where .= "and units.minjing = $user_id ";
		}
		if($request->name){
			$where .= "and units.name LIKE '%$request->name%' ";
		}
		if($request->type != null){
			$where .= "and units.type = $request->type ";
		}
		if($request->xingzhi != null){
			$where .= "and units.xingzhi = $request->xingzhi ";
		}
		if($request->is_del != null){
			$where .= "and units.is_del = $request->is_del ";
		}
		if($request->jibie != null){
			$where .= "and units.is_imp = $request->jibie ";
		}

			if ($id || $name2) {


			if ($id) {
				 if ($area->dengji == 1) {
				 	$city = DB::select("SELECT SUM(units.is_imp = 40) as 一般单位,SUM(units.is_imp = 10) as 省级重点单位,SUM(units.is_imp = 20) as 市级重点单位,SUM(units.is_imp = 30) as 县区级重点单位 FROM units LEFT JOIN area on area.id = units.area WHERE area.cid = ? $where",[$id]);
				 }

				 if ($area->dengji == 2) {
	                $city = DB::select("SELECT SUM(units.is_imp = 40) as 一般单位,SUM(units.is_imp = 10) as 省级重点单位,SUM(units.is_imp = 20) as 市级重点单位,SUM(units.is_imp = 30) as 县区级重点单位 FROM units LEFT JOIN area on area.id = units.org_id WHERE area.cid = ? $where",[$id]);
	             }

	              if ($area->dengji == 3) {
	               	$city = DB::select("SELECT SUM(units.is_imp = 40) as 一般单位,SUM(units.is_imp = 10) as 省级重点单位,SUM(units.is_imp = 20) as 市级重点单位,SUM(units.is_imp = 30) as 县区级重点单位 FROM units LEFT JOIN area on area.id = units.org_id WHERE area.id = ? $where",[$id]);
	             }

			}



			

			if ($name2) {


				if ($name1 == '湖北省') {
					$area = db::table('area')->where('name',$name2)->first();
					if ($area->dengji == 1)
					{
						$aid = $area->id;
						$city = DB::select("SELECT SUM(units.is_imp = 40) as 一般单位,SUM(units.is_imp = 10) as 省级重点单位,SUM(units.is_imp = 20) as 市级重点单位,SUM(units.is_imp = 30) as 县区级重点单位 FROM units LEFT JOIN area on area.id = units.area WHERE area.cid = ? $where",[$aid]);
					}
				}else{
					
					$b = db::table('area')->where('name',$name1)->first();
					$c['cid'] = $b->id;
					$c['name'] = $name2;
					$d = db::table('area')->where($c)->first();
					if ($d) {
						$aid = $d->id;
						$city = DB::select("SELECT SUM(units.is_imp = 40) as 一般单位,SUM(units.is_imp = 10) as 省级重点单位,SUM(units.is_imp = 20) as 市级重点单位,SUM(units.is_imp = 30) as 县区级重点单位 FROM units LEFT JOIN area on area.id = units.org_id WHERE area.cid = ? $where",[$aid]);
					}
	 			}
	 		}

			}else{

				if ($dengji == 1) {
				//获取全省下的级别统计数量
				 $city = DB::select("SELECT SUM(is_imp = 40) as 一般单位,SUM(is_imp = 10) as 省级重点单位,SUM(is_imp = 20) as 市级重点单位,SUM(is_imp = 30) as 县区级重点单位 FROM units WHERE units.id <> -1 $where");
				}


				if ($dengji == 2) {
					$areaid = Auth::guard('admin')->user()->area_id;
					$city = DB::select(" SELECT SUM(units.is_imp = 40) as 一般单位,SUM(units.is_imp = 10) as 省级重点单位,SUM(units.is_imp = 20) as 市级重点单位,SUM(units.is_imp = 30) as 县区级重点单位 FROM units LEFT JOIN area on area.id = units.area WHERE area.id IN ($areaid) $where");
				}

				if ($dengji == 3) {
					$areaid = Auth::guard('admin')->user()->area_id;
					$city = DB::select(" SELECT SUM(units.is_imp = 40) as 一般单位,SUM(units.is_imp = 10) as 省级重点单位,SUM(units.is_imp = 20) as 市级重点单位,SUM(units.is_imp = 30) as 县区级重点单位 FROM units LEFT JOIN area on area.id = units.org_id WHERE area.id IN ($areaid) $where");
					
				}

				if ($dengji == 4) {
					$areaid = Auth::guard('admin')->user()->area_id;
					$city = DB::select(" SELECT SUM(units.is_imp = 40) as 一般单位,SUM(units.is_imp = 10) as 省级重点单位,SUM(units.is_imp = 20) as 市级重点单位,SUM(units.is_imp = 30) as 县区级重点单位 FROM units LEFT JOIN area on area.id = units.org_id WHERE area.id IN ($areaid) $where");
				
				}

			}

			 	 $json = array('city'=>$city);
				 $jcity = json_encode($json,true);
				 echo $jcity;
				 exit;
		}




	public function getdwxz(request $request){
			$dengji = Auth::guard('admin')->user()->dengji;

			if ($dengji == 1) {
				//获取湖北省下单位性质数量
				$count = DB::select("SELECT SUM(xingzhi = '民营') as my,SUM(xingzhi = '国有企业') as gy,SUM(xingzhi = '事业') as sy FROM units");
			}


		 	 $json = array('count'=>$count);
			 $jcity = json_encode($json,true);
			 echo $jcity;
			 exit;
	}


	//重要部位数量
	public function getzdbw(request $request){
		// 根据登录等级获取数量
		$dengji = Auth::guard('admin')->user()->dengji;
		$name1 = $request->name1;
		$name2 = $request->name2;

		$id = $request->id;
		$nid['id'] = $request->id;
		$area = DB::table('area')->where($nid)->first();

		$where = '';
		if(Auth::guard('admin')->user()->dengji == 4){
			$unit_id = db::table('units')->where('minjing',Auth::guard('admin')->user()->id)->pluck('id');
			$array = '';
			foreach ($unit_id as $v){
				$array .= $v.',';
			}
			$array = substr($array, 0, -1);
			$where .= "and zhongyaobuwei.unit_id IN ($array) ";
		}
		if($request->name){
			$where .= "and zhongyaobuwei.name LIKE '%$request->name%'";
		}
		if($request->unit_name){
			$unit_id = db::table('units')->where('name',$request->unit_name)->value('id');
			if($unit_id){
				$where .= "and zhongyaobuwei.unit_id = $unit_id ";
			}else{
				$where .= "and zhongyaobuwei.unit_id = -999 ";
			}
		}


		if ($id || $name2) {

			if ($id) {
				 if ($area->dengji == 1) {
					 $city = DB::select("SELECT area.name,count(1)as value FROM zhongyaobuwei LEFT JOIN units ON units.id = zhongyaobuwei.unit_id LEFT JOIN area ON area.id = units.area WHERE area.cid = ? $where GROUP BY area.name",[$id]);
				 }

				 if ($area->dengji == 2) {
	                $city = DB::select("SELECT area.name,count(1)as value FROM zhongyaobuwei LEFT JOIN units ON units.id = zhongyaobuwei.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.cid = ? $where GROUP BY area.name",[$id]);
	             }

	              if ($area->dengji == 3) {
	               	$city = DB::select("SELECT area.name,count(1)as value FROM zhongyaobuwei LEFT JOIN units ON units.id = zhongyaobuwei.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.id = ? $where GROUP BY area.name",[$id]);
	             }

			}

			if ($name2) {


				if ($name1 == '湖北省') {
					$area = db::table('area')->where('name',$name2)->first();
					if ($area->dengji == 1)
					{
						$aid = $area->id;
						$city = DB::select("SELECT area.name,count(1)as value FROM zhongyaobuwei LEFT JOIN units ON units.id = zhongyaobuwei.unit_id LEFT JOIN area ON area.id = units.area WHERE area.cid = ? $where GROUP BY area.name",[$aid]);
					}
				}else{
					
					$b = db::table('area')->where('name',$name1)->first();
					$c['cid'] = $b->id;
					$c['name'] = $name2;
					$d = db::table('area')->where($c)->first();
					if ($d) {
						$aid = $d->id;
						$city = DB::select("SELECT area.name,count(1)as value FROM zhongyaobuwei LEFT JOIN units ON units.id = zhongyaobuwei.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.cid = ? $where GROUP BY area.name",[$aid]);
					}
	 			}
	 		}
		}else{
			if ($dengji == 1) {
			//获取全省下的级别统计数量
			 $city = DB::select("SELECT area.name,count(1)as value FROM zhongyaobuwei LEFT JOIN units ON units.id = zhongyaobuwei.unit_id LEFT JOIN area ON area.id = units.city WHERE area.cid = 0 and area.dengji = 1 $where GROUP BY area.name");
			}

			if ($dengji == 2) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT area.name,count(1)as value FROM zhongyaobuwei LEFT JOIN units ON units.id = zhongyaobuwei.unit_id LEFT JOIN area ON area.id = units.area WHERE area.id IN ($areaid) $where GROUP BY area.name");
			}

			if ($dengji == 3) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT area.name,count(1)as value FROM zhongyaobuwei LEFT JOIN units ON units.id = zhongyaobuwei.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.id IN ($areaid) $where GROUP BY area.name ");

			}

			if ($dengji == 4) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT area.name,count(1)as value FROM zhongyaobuwei LEFT JOIN units ON units.id = zhongyaobuwei.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.id IN ($areaid) $where GROUP BY area.name ");

			}

			}
			 $json = array('city'=>$city);
			 $jcity = json_encode($json,true);
			 echo $jcity;
			 exit;
	}

	//警情上报数量
	public function getjqsb(request $request){
		// 根据登录等级获取数量
		$dengji = Auth::guard('admin')->user()->dengji;
		$name1 = $request->name1;
		$name2 = $request->name2;

		$id = $request->id;
		$nid['id'] = $request->id;
		$area = DB::table('area')->where($nid)->first();

		$where = '';
		if(Auth::guard('admin')->user()->dengji == 4){
			$unit_id = db::table('units')->where('minjing',Auth::guard('admin')->user()->id)->pluck('id');
			$array = '';
			foreach ($unit_id as $v){
				$array .= $v.',';
			}
			$array = substr($array, 0, -1);
			$where .= "and jqsb.unit_id IN ($array) ";
		}
		if($request->created_at){
			$where .= "and jqsb.created_at LIKE '%$request->created_at%' ";
		}
		if($request->police_cl != null){
			$where .= "and jqsb.police_cl = $request->police_cl ";
		}
		if($request->sbren){
			$where .= "and jqsb.sbren LIKE '%$request->sbren%' ";
		}
		if($request->unit_name){
			$unit_id = db::table('units')->where('name',$request->unit_name)->value('id');
			if($unit_id){
				$where .= "and jqsb.unit_id = $unit_id ";
			}else{
				$where .= "and jqsb.unit_id = -999 ";
			}
		}
		if($request->chuli_time != null){
			if($request->input('chuli_time') == 1){
				$where .= "and jqsb.chuli_time <= 3600*24 ";
			}
			if($request->input('chuli_time') == 2){
				$where .= "and jqsb.chuli_time > 3600*24 and jqsb.chuli_time <= 3600*24*3 ";
			}
			if($request->input('chuli_time') == 3){
				$where .= "and jqsb.chuli_time > 3600*24*3 and jqsb.chuli_time <= 3600*24*7 ";
			}
			if($request->input('chuli_time') == 4){
				$where .= "and jqsb.chuli_time > 3600*24*7 and jqsb.chuli_time <= 3600*24*15 ";
			}
			if($request->input('chuli_time') == 5){
				$where .= "and jqsb.chuli_time > 3600*24*15 ";
			}
		}

		if ($id || $name2) {

			if ($id) {
				if ($area->dengji == 1) {
					$city = DB::select("SELECT area.name,count(1)as value FROM jqsb LEFT JOIN units ON units.id = jqsb.unit_id LEFT JOIN area ON area.id = units.area WHERE area.cid = ? $where GROUP BY area.name",[$id]);
				}

				if ($area->dengji == 2) {
					$city = DB::select("SELECT area.name,count(1)as value FROM jqsb LEFT JOIN units ON units.id = jqsb.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.cid = ? $where GROUP BY area.name",[$id]);
				}

				if ($area->dengji == 3) {
					$city = DB::select("SELECT area.name,count(1)as value FROM jqsb LEFT JOIN units ON units.id = jqsb.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.id = ? $where GROUP BY area.name",[$id]);
				}

			}

			if ($name2) {


				if ($name1 == '湖北省') {
					$area = db::table('area')->where('name',$name2)->first();
					if ($area->dengji == 1)
					{
						$aid = $area->id;
						$city = DB::select("SELECT area.name,count(1)as value FROM jqsb LEFT JOIN units ON units.id = jqsb.unit_id LEFT JOIN area ON area.id = units.area WHERE area.cid = ? $where GROUP BY area.name",[$aid]);
					}
				}else{

					$b = db::table('area')->where('name',$name1)->first();
					$c['cid'] = $b->id;
					$c['name'] = $name2;
					$d = db::table('area')->where($c)->first();
					if ($d) {
						$aid = $d->id;
						$city = DB::select("SELECT area.name,count(1)as value FROM jqsb LEFT JOIN units ON units.id = jqsb.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.cid = ? $where GROUP BY area.name",[$aid]);
					}
				}
			}
		}else{
			if ($dengji == 1) {
				//获取全省下的级别统计数量
				$city = DB::select("SELECT area.name,count(1)as value FROM jqsb LEFT JOIN units ON units.id = jqsb.unit_id LEFT JOIN area ON area.id = units.city WHERE area.cid = 0 and area.dengji = 1 $where GROUP BY area.name");
			}

			if ($dengji == 2) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT area.name,count(1)as value FROM jqsb LEFT JOIN units ON units.id = jqsb.unit_id LEFT JOIN area ON area.id = units.area WHERE area.id IN ($areaid) $where GROUP BY area.name");
			}

			if ($dengji == 3) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT area.name,count(1)as value FROM jqsb LEFT JOIN units ON units.id = jqsb.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.id IN ($areaid) $where GROUP BY area.name ");

			}

			if ($dengji == 4) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT area.name,count(1)as value FROM jqsb LEFT JOIN units ON units.id = jqsb.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.id IN ($areaid) $where GROUP BY area.name ");

			}

		}
		$json = array('city'=>$city);
		$jcity = json_encode($json,true);
		echo $jcity;
		exit;
	}

	//人员审核数量
	public function getrysh(request $request){
		// 根据登录等级获取数量
		$dengji = Auth::guard('admin')->user()->dengji;
		$name1 = $request->name1;
		$name2 = $request->name2;

		$id = $request->id;
		$nid['id'] = $request->id;
		$area = DB::table('area')->where($nid)->first();

		$where = '';
		if(Auth::guard('admin')->user()->dengji == 4){
			$unit_id = db::table('units')->where('minjing',Auth::guard('admin')->user()->id)->pluck('id');
			$array = '';
			foreach ($unit_id as $v){
				$array .= $v.',';
			}
			$array = substr($array, 0, -1);
			$where .= "and rysh.unit_id IN ($array) ";
		}
		if($request->created_at){
			$where .= "and rysh.created_at LIKE '%$request->created_at%' ";
		}
		if($request->unit_name){
			$unit_id = db::table('units')->where('name',$request->unit_name)->value('id');
			if($unit_id){
				$where .= "and rysh.unit_id = $unit_id ";
			}else{
				$where .= "and rysh.unit_id = -999 ";
			}
		}
		if($request->sfzh){
			$where .= "and rysh.sfzh LIKE '%$request->sfzh%' ";
		}
		if($request->hcry){
			$where .= "and rysh.hcry LIKE '%$request->hcry%' ";
		}
		if($request->police_cl != null){
			$where .= "and rysh.police_cl = $request->police_cl ";
		}
		if($request->chuli_time != null){
			if($request->input('chuli_time') == 1){
				$where .= "and rysh.chuli_time <= 3600*24 ";
			}
			if($request->input('chuli_time') == 2){
				$where .= "and rysh.chuli_time > 3600*24 and rysh.chuli_time <= 3600*24*3 ";
			}
			if($request->input('chuli_time') == 3){
				$where .= "and rysh.chuli_time > 3600*24*3 and rysh.chuli_time <= 3600*24*7 ";
			}
			if($request->input('chuli_time') == 4){
				$where .= "and rysh.chuli_time > 3600*24*7 and rysh.chuli_time <= 3600*24*15 ";
			}
			if($request->input('chuli_time') == 5){
				$where .= "and rysh.chuli_time > 3600*24*15 ";
			}
		}

		if ($id || $name2) {

			if ($id) {
				if ($area->dengji == 1) {
					$city = DB::select("SELECT area.name,count(1)as value FROM rysh LEFT JOIN units ON units.id = rysh.unit_id LEFT JOIN area ON area.id = units.area WHERE area.cid = ? $where GROUP BY area.name",[$id]);
				}

				if ($area->dengji == 2) {
					$city = DB::select("SELECT area.name,count(1)as value FROM rysh LEFT JOIN units ON units.id = rysh.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.cid = ? $where GROUP BY area.name",[$id]);
				}

				if ($area->dengji == 3) {
					$city = DB::select("SELECT area.name,count(1)as value FROM rysh LEFT JOIN units ON units.id = rysh.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.id = ? $where GROUP BY area.name",[$id]);
				}

			}

			if ($name2) {


				if ($name1 == '湖北省') {
					$area = db::table('area')->where('name',$name2)->first();
					if ($area->dengji == 1)
					{
						$aid = $area->id;
						$city = DB::select("SELECT area.name,count(1)as value FROM rysh LEFT JOIN units ON units.id = rysh.unit_id LEFT JOIN area ON area.id = units.area WHERE area.cid = ? $where GROUP BY area.name",[$aid]);
					}
				}else{

					$b = db::table('area')->where('name',$name1)->first();
					$c['cid'] = $b->id;
					$c['name'] = $name2;
					$d = db::table('area')->where($c)->first();
					if ($d) {
						$aid = $d->id;
						$city = DB::select("SELECT area.name,count(1)as value FROM rysh LEFT JOIN units ON units.id = rysh.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.cid = ? $where GROUP BY area.name",[$aid]);
					}
				}
			}
		}else{
			if ($dengji == 1) {
				//获取全省下的级别统计数量
				$city = DB::select("SELECT area.name,count(1)as value FROM rysh LEFT JOIN units ON units.id = rysh.unit_id LEFT JOIN area ON area.id = units.city WHERE area.cid = 0 and area.dengji = 1 $where GROUP BY area.name");
			}

			if ($dengji == 2) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT area.name,count(1)as value FROM rysh LEFT JOIN units ON units.id = rysh.unit_id LEFT JOIN area ON area.id = units.area WHERE area.id IN ($areaid) $where GROUP BY area.name");
			}

			if ($dengji == 3) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT area.name,count(1)as value FROM rysh LEFT JOIN units ON units.id = rysh.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.id IN ($areaid) $where GROUP BY area.name ");

			}

			if ($dengji == 4) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT area.name,count(1)as value FROM rysh LEFT JOIN units ON units.id = rysh.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.id IN ($areaid) $where GROUP BY area.name ");

			}

		}
		$json = array('city'=>$city);
		$jcity = json_encode($json,true);
		echo $jcity;
		exit;
	}

	//线索举报数量
	public function getxsjb(request $request){
		// 根据登录等级获取数量
		$dengji = Auth::guard('admin')->user()->dengji;
		$name1 = $request->name1;
		$name2 = $request->name2;

		$id = $request->id;
		$nid['id'] = $request->id;
		$area = DB::table('area')->where($nid)->first();

		$where = '';
		if(Auth::guard('admin')->user()->dengji == 4){
			$unit_id = db::table('units')->where('minjing',Auth::guard('admin')->user()->id)->pluck('id');
			$array = '';
			foreach ($unit_id as $v){
				$array .= $v.',';
			}
			$array = substr($array, 0, -1);
			$where .= "and xiansuo.unit_id IN ($array) ";
		}
		if($request->unit_name){
			$unit_id = db::table('units')->where('name',$request->unit_name)->value('id');
			if($unit_id){
				$where .= "and xiansuo.unit_id = $unit_id ";
			}else{
				$where .= "and xiansuo.unit_id = -999 ";
			}
		}
		if($request->created_at){
			$where .= "and xiansuo.created_at LIKE '%$request->created_at%' ";
		}
		if($request->police_cl != null){
			$where .= "and xiansuo.police_cl = $request->police_cl ";
		}
		if($request->jbr){
			$where .= "and xiansuo.jbr LIKE '%$request->jbr%' ";
		}
		if($request->chuli_time != null){
			if($request->input('chuli_time') == 1){
				$where .= "and xiansuo.chuli_time <= 3600*24 ";
			}
			if($request->input('chuli_time') == 2){
				$where .= "and xiansuo.chuli_time > 3600*24 and xiansuo.chuli_time <= 3600*24*3 ";
			}
			if($request->input('chuli_time') == 3){
				$where .= "and xiansuo.chuli_time > 3600*24*3 and xiansuo.chuli_time <= 3600*24*7 ";
			}
			if($request->input('chuli_time') == 4){
				$where .= "and xiansuo.chuli_time > 3600*24*7 and xiansuo.chuli_time <= 3600*24*15 ";
			}
			if($request->input('chuli_time') == 5){
				$where .= "and xiansuo.chuli_time > 3600*24*15 ";
			}
		}

		if ($id || $name2) {

			if ($id) {
				if ($area->dengji == 1) {
					$city = DB::select("SELECT area.name,count(1)as value FROM xiansuo LEFT JOIN units ON units.id = xiansuo.unit_id LEFT JOIN area ON area.id = units.area WHERE area.cid = ? $where GROUP BY area.name",[$id]);
				}

				if ($area->dengji == 2) {
					$city = DB::select("SELECT area.name,count(1)as value FROM xiansuo LEFT JOIN units ON units.id = xiansuo.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.cid = ? $where GROUP BY area.name",[$id]);
				}

				if ($area->dengji == 3) {
					$city = DB::select("SELECT area.name,count(1)as value FROM xiansuo LEFT JOIN units ON units.id = xiansuo.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.id = ? $where GROUP BY area.name",[$id]);
				}

			}

			if ($name2) {


				if ($name1 == '湖北省') {
					$area = db::table('area')->where('name',$name2)->first();
					if ($area->dengji == 1)
					{
						$aid = $area->id;
						$city = DB::select("SELECT area.name,count(1)as value FROM xiansuo LEFT JOIN units ON units.id = xiansuo.unit_id LEFT JOIN area ON area.id = units.area WHERE area.cid = ? $where GROUP BY area.name",[$aid]);
					}
				}else{

					$b = db::table('area')->where('name',$name1)->first();
					$c['cid'] = $b->id;
					$c['name'] = $name2;
					$d = db::table('area')->where($c)->first();
					if ($d) {
						$aid = $d->id;
						$city = DB::select("SELECT area.name,count(1)as value FROM xiansuo LEFT JOIN units ON units.id = xiansuo.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.cid = ? $where GROUP BY area.name",[$aid]);
					}
				}
			}
		}else{
			if ($dengji == 1) {
				//获取全省下的级别统计数量
				$city = DB::select("SELECT area.name,count(1)as value FROM xiansuo LEFT JOIN units ON units.id = xiansuo.unit_id LEFT JOIN area ON area.id = units.city WHERE area.cid = 0 and area.dengji = 1 $where GROUP BY area.name");
			}

			if ($dengji == 2) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT area.name,count(1)as value FROM xiansuo LEFT JOIN units ON units.id = xiansuo.unit_id LEFT JOIN area ON area.id = units.area WHERE area.id IN ($areaid) $where GROUP BY area.name");
			}

			if ($dengji == 3) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT area.name,count(1)as value FROM xiansuo LEFT JOIN units ON units.id = xiansuo.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.id IN ($areaid) $where GROUP BY area.name ");

			}

			if ($dengji == 4) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT area.name,count(1)as value FROM xiansuo LEFT JOIN units ON units.id = xiansuo.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.id IN ($areaid) $where GROUP BY area.name ");

			}

		}
		$json = array('city'=>$city);
		$jcity = json_encode($json,true);
		echo $jcity;
		exit;
	}

	//安全检查数量
	public function getaqjc(request $request){
		// 根据登录等级获取数量
		$dengji = Auth::guard('admin')->user()->dengji;
		$name1 = $request->name1;
		$name2 = $request->name2;

		$id = $request->id;
		$nid['id'] = $request->id;
		$area = DB::table('area')->where($nid)->first();

		$where = '';
		if(Auth::guard('admin')->user()->dengji == 4){
			$unit_id = db::table('units')->where('minjing',Auth::guard('admin')->user()->id)->pluck('id');
			$array = '';
			foreach ($unit_id as $v){
				$array .= $v.',';
			}
			$array = substr($array, 0, -1);
			$where .= "and jiancha.unit_id IN ($array) ";
		}
		if($request->created_at){
			$where .= "and jiancha.created_at LIKE '%$request->created_at%' ";
		}
		if($request->unit_name){
			$unit_id = db::table('units')->where('name',$request->unit_name)->value('id');
			if($unit_id){
				$where .= "and jiancha.unit_id = $unit_id ";
			}else{
				$where .= "and jiancha.unit_id = -999 ";
			}
		}
		if($request->name){
			$user_id = db::table('admin_users')->where('name',$request->name)->value('id');
			$where .= "and jiancha.user_id = $user_id ";
		}
		if($request->status != null){
			$where .= "and jiancha.status = $request->status ";
		}
		if($request->aqjc_type != null){
			$where .= "and jiancha.aqjc_type = $request->aqjc_type ";
		}

		$count = 0;
		if ($id || $name2) {

			if ($id) {
				if ($area->dengji == 1) {
					$city = DB::select("SELECT area.name,count(1)as value FROM jiancha LEFT JOIN units ON units.id = jiancha.unit_id LEFT JOIN area ON area.id = units.area WHERE area.cid = ? $where GROUP BY area.name",[$id]);
				}

				if ($area->dengji == 2) {
					$city = DB::select("SELECT area.name,count(1)as value FROM jiancha LEFT JOIN units ON units.id = jiancha.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.cid = ? $where GROUP BY area.name",[$id]);
				}

				if ($area->dengji == 3) {
					$city = DB::select("SELECT area.name,count(1)as value FROM jiancha LEFT JOIN units ON units.id = jiancha.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.id = ? $where GROUP BY area.name",[$id]);
				}

			}

			if ($name2) {


				if ($name1 == '湖北省') {
					$area = db::table('area')->where('name',$name2)->first();
					if ($area->dengji == 1)
					{
						$aid = $area->id;
						$city = DB::select("SELECT area.name,count(1)as value FROM jiancha LEFT JOIN units ON units.id = jiancha.unit_id LEFT JOIN area ON area.id = units.area WHERE area.cid = ? $where GROUP BY area.name",[$aid]);
						$count = db::table('jiancha')->where('city',$aid)->count();
					}
				}else{

					$b = db::table('area')->where('name',$name1)->first();
					$c['cid'] = $b->id;
					$c['name'] = $name2;
					$d = db::table('area')->where($c)->first();
					if ($d) {
						$aid = $d->id;
						$city = DB::select("SELECT area.name,count(1)as value FROM jiancha LEFT JOIN units ON units.id = jiancha.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.cid = ? $where GROUP BY area.name",[$aid]);
					}
				}
			}
		}else{
			if ($dengji == 1) {
				//获取全省下的级别统计数量
				$city = DB::select("SELECT area.name,count(1)as value FROM jiancha LEFT JOIN units ON units.id = jiancha.unit_id LEFT JOIN area ON area.id = units.city WHERE area.cid = 0 and area.dengji = 1 $where GROUP BY area.name");
				$count = db::table('jiancha')->count();
			}

			if ($dengji == 2) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT area.name,count(1)as value FROM jiancha LEFT JOIN units ON units.id = jiancha.unit_id LEFT JOIN area ON area.id = units.area WHERE area.id IN ($areaid) $where GROUP BY area.name");
				$count = db::table('jiancha')->count();
			}

			if ($dengji == 3) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT area.name,count(1)as value FROM jiancha LEFT JOIN units ON units.id = jiancha.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.id IN ($areaid) $where GROUP BY area.name ");
				$count = db::table('jiancha')->count();
			}

			if ($dengji == 4) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT area.name,count(1)as value FROM jiancha LEFT JOIN units ON units.id = jiancha.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.id IN ($areaid) $where GROUP BY area.name ");
				$count = db::table('jiancha')->count();
			}

		}
		$json = array('city'=>$city,'count'=>$count);
		$jcity = json_encode($json,true);
		echo $jcity;
		exit;
	}


	//保卫人员

		public function getbwry(request $request){
			// 根据登录等级获取数量
			$dengji = Auth::guard('admin')->user()->dengji;
			$name1 = $request->name1;
			$name2 = $request->name2;

			$id = $request->id;
			$nid['id'] = $request->id;
			$area = DB::table('area')->where($nid)->first();

			$where = '';

			if(Auth::guard('admin')->user()->dengji == 4){
				$unit_id = db::table('units')->where('minjing',Auth::guard('admin')->user()->id)->pluck('id');
				$array = '';
				foreach ($unit_id as $v){
					$array .= $v.',';
				}
				$array = substr($array, 0, -1);
				$where .= "and baoweirenyuan.unit_id IN ($array) ";
			}
			if($request->name){
				$where .= "and baoweirenyuan.name LIKE '%$request->name%' ";
			}
			if($request->unit_name){
				$unit_id = db::table('units')->where('name',$request->unit_name)->value('id');
				if($unit_id){
					$where .= "and baoweirenyuan.unit_id = $unit_id ";
				}else{
					$where .= "and baoweirenyuan.unit_id = -999 ";
				}
			}
			if($request->id_number){
				$where .= "and baoweirenyuan.id_number LIKE '%$request->id_number%' ";
			}
			if ($id || $name2) {

			if ($id) {
				 if ($area->dengji == 1) {
					 $city = DB::select("SELECT area.name,count(1)as value FROM baoweirenyuan LEFT JOIN units ON units.id = baoweirenyuan.unit_id LEFT JOIN area ON area.id = units.area WHERE area.cid = ? $where GROUP BY area.name",[$id]);
				 }

				 if ($area->dengji == 2) {
	              	$city = DB::select("SELECT area.name,count(1)as value FROM baoweirenyuan LEFT JOIN units ON units.id = baoweirenyuan.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.cid = ? $where GROUP BY area.name",[$id]);
	             }

	              if ($area->dengji == 3) {
	             	 $city = DB::select("SELECT area.name,count(1)as value FROM baoweirenyuan LEFT JOIN units ON units.id = baoweirenyuan.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.id = ? $where GROUP BY area.name",[$id]);
	             }

			}





			if ($name2) {


				if ($name1 == '湖北省') {
					$area = db::table('area')->where('name',$name2)->first();
					if ($area->dengji == 1)
					{
						$aid = $area->id;
						$city = DB::select("SELECT area.name,count(1)as value FROM baoweirenyuan LEFT JOIN units ON units.id = baoweirenyuan.unit_id LEFT JOIN area ON area.id = units.area WHERE area.cid = ? GROUP BY area.name",[$aid]);
					}
				}else{
					
					$b = db::table('area')->where('name',$name1)->first();
					$c['cid'] = $b->id;
					$c['name'] = $name2;
					$d = db::table('area')->where($c)->first();
					if ($d) {
						$aid = $d->id;
						$city = DB::select("SELECT area.name,count(1)as value FROM baoweirenyuan LEFT JOIN units ON units.id = baoweirenyuan.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.cid = ? GROUP BY area.name",[$aid]);
					
					}
	 			}
	 		}

			}else{

				if ($dengji == 1) {
				//获取全省下的级别统计数量
				 $city = DB::select("SELECT area.name,count(1)as value FROM baoweirenyuan LEFT JOIN units ON units.id = baoweirenyuan.unit_id LEFT JOIN area ON area.id = units.city WHERE area.cid = 0 and area.dengji = 1 $where GROUP BY area.name");
				}


				if ($dengji == 2) {
					$areaid = Auth::guard('admin')->user()->area_id;
					$city = DB::select(" SELECT area.name,count(1)as value FROM baoweirenyuan LEFT JOIN units ON units.id = baoweirenyuan.unit_id LEFT JOIN area ON area.id = units.area WHERE area.id IN ($areaid) $where GROUP BY area.name");
				}

				if ($dengji == 3) {
					$areaid = Auth::guard('admin')->user()->area_id;
					$city = DB::select(" SELECT area.name,count(1)as value FROM baoweirenyuan LEFT JOIN units ON units.id = baoweirenyuan.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.id IN ($areaid) $where GROUP BY area.name ");
					
				}

				if ($dengji == 4) {
					$areaid = Auth::guard('admin')->user()->area_id;
					$city = DB::select(" SELECT area.name,count(1)as value FROM baoweirenyuan LEFT JOIN units ON units.id = baoweirenyuan.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.id IN ($areaid) $where GROUP BY area.name ");
				
				}

			}

			 	 $json = array('city'=>$city);
				 $jcity = json_encode($json,true);
				 echo $jcity;
				 exit;
	}

	//重点人员

		public function getzdry(request $request){
			// 根据登录等级获取数量
			$dengji = Auth::guard('admin')->user()->dengji;
			$name1 = $request->name1;
			$name2 = $request->name2;

			$id = $request->id;
			$nid['id'] = $request->id;
			$area = DB::table('area')->where($nid)->first();

			$where = '';
			if(Auth::guard('admin')->user()->dengji == 4){
				$unit_id = db::table('units')->where('minjing',Auth::guard('admin')->user()->id)->pluck('id');
				$array = '';
				foreach ($unit_id as $v){
					$array .= $v.',';
				}
				$array = substr($array, 0, -1);
				$where .= "and zhongdianrenyuan.unit_id IN ($array) ";
			}
			if($request->name){
				$where .= "and zhongdianrenyuan.name LIKE '%$request->name%' ";
			}
			if($request->unit_name){
				$unit_id = db::table('units')->where('name',$request->unit_name)->value('id');
				if($unit_id){
					$where .= "and zhongdianrenyuan.unit_id = $unit_id ";
				}else{
					$where .= "and zhongdianrenyuan.unit_id = -999 ";
				}
			}
			if($request->id_number){
				$where .= "and zhongdianrenyuan.id_number LIKE '%$request->id_number%' ";
			}

			if ($id || $name2) {

			if ($id) {
				 if ($area->dengji == 1) {
					$city = DB::select("SELECT area.name,count(1)as value FROM zhongdianrenyuan LEFT JOIN units ON units.id = zhongdianrenyuan.unit_id LEFT JOIN area ON area.id = units.area WHERE area.cid = ? $where GROUP BY area.name",[$id]);
				 }

				 if ($area->dengji == 2) {
	              		$city = DB::select("SELECT area.name,count(1)as value FROM zhongdianrenyuan LEFT JOIN units ON units.id = zhongdianrenyuan.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.cid = ? $where GROUP BY area.name",[$id]);
	             }

	             if ($area->dengji == 3) {
	             		$city = DB::select("SELECT area.name,count(1)as value FROM zhongdianrenyuan LEFT JOIN units ON units.id = zhongdianrenyuan.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.id = ? $where GROUP BY area.name",[$id]);
	             }

			}



			if ($name2) {


				if ($name1 == '湖北省') {
					$area = db::table('area')->where('name',$name2)->first();
					if ($area->dengji == 1)
					{
						$aid = $area->id;
						$city = DB::select("SELECT area.name,count(1)as value FROM zhongdianrenyuan LEFT JOIN units ON units.id = zhongdianrenyuan.unit_id LEFT JOIN area ON area.id = units.area WHERE area.cid = ? GROUP BY area.name",[$aid]);
					}
				}else{

					$b = db::table('area')->where('name',$name1)->first();
					$c['cid'] = $b->id;
					$c['name'] = $name2;
					$d = db::table('area')->where($c)->first();
					if ($d) {
						$aid = $d->id;
						$city = DB::select("SELECT area.name,count(1)as value FROM zhongdianrenyuan LEFT JOIN units ON units.id = zhongdianrenyuan.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.cid = ? GROUP BY area.name",[$aid]);
					}
	 			}
	 		}

			}else{

				if ($dengji == 1) {
				//获取全省下的级别统计数量
				 $city = DB::select("SELECT area.name,count(1)as value FROM zhongdianrenyuan LEFT JOIN units ON units.id = zhongdianrenyuan.unit_id LEFT JOIN area ON area.id = units.city WHERE area.cid = 0 and area.dengji = 1 $where GROUP BY area.name");
				}


				if ($dengji == 2) {
					$areaid = Auth::guard('admin')->user()->area_id;
					$city = DB::select(" SELECT area.name,count(1)as value FROM zhongdianrenyuan LEFT JOIN units ON units.id = zhongdianrenyuan.unit_id LEFT JOIN area ON area.id = units.area WHERE area.id IN ($areaid) $where GROUP BY area.name");
				}

				if ($dengji == 3) {
					$areaid = Auth::guard('admin')->user()->area_id;
					$city = DB::select(" SELECT area.name,count(1)as value FROM zhongdianrenyuan LEFT JOIN units ON units.id = zhongdianrenyuan.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.id IN ($areaid) $where GROUP BY area.name ");

				}

				if ($dengji == 4) {
					$areaid = Auth::guard('admin')->user()->area_id;
					$city = DB::select(" SELECT area.name,count(1)as value FROM zhongdianrenyuan LEFT JOIN units ON units.id = zhongdianrenyuan.unit_id LEFT JOIN area ON area.id = units.org_id WHERE area.id IN ($areaid) $where GROUP BY area.name ");

				}

			}

			 	 $json = array('city'=>$city);
				 $jcity = json_encode($json,true);
				 echo $jcity;
				 exit;
	}

	//单位状态
	public function getdwzt(request $request){
			// 根据登录等级获取数量
			$dengji = Auth::guard('admin')->user()->dengji;
			$name1 = $request->name1;
			$name2 = $request->name2;

			$id = $request->id;
			$nid['id'] = $request->id;
			$area = DB::table('area')->where($nid)->first();

		$where = '';
		if(Auth::guard('admin')->user()->dengji == 4){
			$user_id = Auth::guard('admin')->user()->id;
			$where .= "and units.minjing = $user_id ";
		}
		if($request->name){
			$where .= "and units.name LIKE '%$request->name%' ";
		}
		if($request->type != null){
			$where .= "and units.type = $request->type ";
		}
		if($request->xingzhi != null){
			$where .= "and units.xingzhi = $request->xingzhi ";
		}
		if($request->is_del != null){
			$where .= "and units.is_del = $request->is_del ";
		}
		if($request->jibie != null){
			$where .= "and units.is_imp = $request->jibie ";
		}

			if ($id || $name2) {

			if ($id) {
				 if ($area->dengji == 1) {
					$city = DB::select("SELECT SUM(units.is_del = 0) as 实有,SUM(units.is_del = 1) as 注销,SUM(units.is_del = 2) as 合并 FROM units LEFT JOIN area on area.id = units.area WHERE area.cid = ? $where",[$id]);
				 }

				 if ($area->dengji == 2) {
	              		$city = DB::select("SELECT SUM(units.is_del = 0) as 实有,SUM(units.is_del = 1) as 注销,SUM(units.is_del = 2) as 合并 FROM units LEFT JOIN area on area.id = units.org_id WHERE area.cid = ? $where",[$id]);
	             }

	             if ($area->dengji == 3) {
	             		$city = DB::select("SELECT SUM(units.is_del = 0) as 实有,SUM(units.is_del = 1) as 注销,SUM(units.is_del = 2) as 合并 FROM units LEFT JOIN area on area.id = units.org_id WHERE area.id = ? $where",[$id]);
	             }

			}


			

			if ($name2) {


				if ($name1 == '湖北省') {
					$area = db::table('area')->where('name',$name2)->first();
					if ($area->dengji == 1)
					{
						$aid = $area->id;
						$city = DB::select("SELECT SUM(units.is_del = 0) as 实有,SUM(units.is_del = 1) as 注销,SUM(units.is_del = 2) as 合并 FROM units LEFT JOIN area on area.id = units.area WHERE area.cid = ? $where",[$aid]);
					}
				}else{
					
					$b = db::table('area')->where('name',$name1)->first();
					$c['cid'] = $b->id;
					$c['name'] = $name2;
					$d = db::table('area')->where($c)->first();
					if ($d) {
						$aid = $d->id;
						$city = DB::select("SELECT SUM(units.is_del = 0) as 实有,SUM(units.is_del = 1) as 注销,SUM(units.is_del = 2) as 合并 FROM units LEFT JOIN area on area.id = units.org_id WHERE area.cid = ? $where",[$aid]);
					}
	 			}
	 		}

			}else{

				if ($dengji == 1) {
				//获取全省下的级别统计数量
				 $city = DB::select("SELECT SUM(units.is_del = 0) as 实有,SUM(units.is_del = 1) as 注销,SUM(units.is_del = 2) as 合并 FROM units WHERE units.id <> -1 $where");
				}


				if ($dengji == 2) {
					$areaid = Auth::guard('admin')->user()->area_id;
					$city = DB::select(" SELECT SUM(units.is_del = 0) as 实有,SUM(units.is_del = 1) as 注销,SUM(units.is_del = 2) as 合并 FROM units LEFT JOIN area on area.id = units.area WHERE area.id IN ($areaid) $where");
				}

				if ($dengji == 3) {
					$areaid = Auth::guard('admin')->user()->area_id;
					$city = DB::select(" SELECT SUM(units.is_del = 0) as 实有,SUM(units.is_del = 1) as 注销,SUM(units.is_del = 2) as 合并 FROM units LEFT JOIN area on area.id = units.org_id WHERE area.id IN ($areaid) $where");
					
				}

				if ($dengji == 4) {
					$areaid = Auth::guard('admin')->user()->area_id;
					$city = DB::select(" SELECT SUM(units.is_del = 0) as 实有,SUM(units.is_del = 1) as 注销,SUM(units.is_del = 2) as 合并 FROM units LEFT JOIN area on area.id = units.org_id WHERE area.id IN ($areaid) $where");
				
				}

			}

			 	 $json = array('city'=>$city);
				 $jcity = json_encode($json,true);
				 echo $jcity;
				 exit;
		}

	//单位状态
	public function getxingzhi(request $request){
		// 根据登录等级获取数量
		$dengji = Auth::guard('admin')->user()->dengji;
		$name1 = $request->name1;
		$name2 = $request->name2;

		$id = $request->id;
		$nid['id'] = $request->id;
		$area = DB::table('area')->where($nid)->first();

		$where = '';
		if(Auth::guard('admin')->user()->dengji == 4){
			$user_id = Auth::guard('admin')->user()->id;
			$where .= "and units.minjing = $user_id ";
		}
		if($request->name){
			$where .= "and units.name LIKE '%$request->name%' ";
		}
		if($request->type != null){
			$where .= "and units.type = $request->type ";
		}
		if($request->xingzhi != null){
			$where .= "and units.xingzhi = $request->xingzhi ";
		}
		if($request->is_del != null){
			$where .= "and units.is_del = $request->is_del ";
		}
		if($request->jibie != null){
			$where .= "and units.is_imp = $request->jibie ";
		}

		if ($id || $name2) {

			if ($id) {
				if ($area->dengji == 1) {
					$city = DB::select("SELECT SUM(units.xingzhi = 10) as 国有,SUM(units.xingzhi = 20) as 民营,SUM(units.xingzhi = 30) as 股份,SUM(units.xingzhi = 40) as 合资,SUM(units.xingzhi = 50) as 外资,SUM(units.xingzhi = 60) as 个体 FROM units LEFT JOIN area on area.id = units.area WHERE area.cid = ? $where",[$id]);
				}

				if ($area->dengji == 2) {
					$city = DB::select("SELECT SUM(units.xingzhi = 10) as 国有,SUM(units.xingzhi = 20) as 民营,SUM(units.xingzhi = 30) as 股份,SUM(units.xingzhi = 40) as 合资,SUM(units.xingzhi = 50) as 外资,SUM(units.xingzhi = 60) as 个体 FROM units LEFT JOIN area on area.id = units.org_id WHERE area.cid = ? $where",[$id]);
				}

				if ($area->dengji == 3) {
					$city = DB::select("SELECT SUM(units.xingzhi = 10) as 国有,SUM(units.xingzhi = 20) as 民营,SUM(units.xingzhi = 30) as 股份,SUM(units.xingzhi = 40) as 合资,SUM(units.xingzhi = 50) as 外资,SUM(units.xingzhi = 60) as 个体 FROM units LEFT JOIN area on area.id = units.org_id WHERE area.id = ? $where",[$id]);
				}

			}




			if ($name2) {


				if ($name1 == '湖北省') {
					$area = db::table('area')->where('name',$name2)->first();
					if ($area->dengji == 1)
					{
						$aid = $area->id;
						$city = DB::select("SELECT SUM(units.xingzhi = 10) as 国有,SUM(units.xingzhi = 20) as 民营,SUM(units.xingzhi = 30) as 股份,SUM(units.xingzhi = 40) as 合资,SUM(units.xingzhi = 50) as 外资,SUM(units.xingzhi = 60) as 个体 FROM units LEFT JOIN area on area.id = units.area WHERE area.cid = ? $where",[$aid]);
					}
				}else{

					$b = db::table('area')->where('name',$name1)->first();
					$c['cid'] = $b->id;
					$c['name'] = $name2;
					$d = db::table('area')->where($c)->first();
					if ($d) {
						$aid = $d->id;
						$city = DB::select("SELECT SUM(units.xingzhi = 10) as 国有,SUM(units.xingzhi = 20) as 民营,SUM(units.xingzhi = 30) as 股份,SUM(units.xingzhi = 40) as 合资,SUM(units.xingzhi = 50) as 外资,SUM(units.xingzhi = 60) as 个体 FROM units LEFT JOIN area on area.id = units.org_id WHERE area.cid = ? $where",[$aid]);
					}
				}
			}

		}else{

			if ($dengji == 1) {
				//获取全省下的级别统计数量
				$city = DB::select("SELECT SUM(units.xingzhi = 10) as 国有,SUM(units.xingzhi = 20) as 民营,SUM(units.xingzhi = 30) as 股份,SUM(units.xingzhi = 40) as 合资,SUM(units.xingzhi = 50) as 外资,SUM(units.xingzhi = 60) as 个体 FROM units WHERE units.id <> -1 $where");
			}


			if ($dengji == 2) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT SUM(units.xingzhi = 10) as 国有,SUM(units.xingzhi = 20) as 民营,SUM(units.xingzhi = 30) as 股份,SUM(units.xingzhi = 40) as 合资,SUM(units.xingzhi = 50) as 外资,SUM(units.xingzhi = 60) as 个体 FROM units LEFT JOIN area on area.id = units.area WHERE area.id IN ($areaid) $where");
			}

			if ($dengji == 3) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT SUM(units.xingzhi = 10) as 国有,SUM(units.xingzhi = 20) as 民营,SUM(units.xingzhi = 30) as 股份,SUM(units.xingzhi = 40) as 合资,SUM(units.xingzhi = 50) as 外资,SUM(units.xingzhi = 60) as 个体 FROM units LEFT JOIN area on area.id = units.org_id WHERE area.id IN ($areaid) $where");

			}

			if ($dengji == 4) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT SUM(units.xingzhi = 10) as 国有,SUM(units.xingzhi = 20) as 民营,SUM(units.xingzhi = 30) as 股份,SUM(units.xingzhi = 40) as 合资,SUM(units.xingzhi = 50) as 外资,SUM(units.xingzhi = 60) as 个体 FROM units LEFT JOIN area on area.id = units.org_id WHERE area.id IN ($areaid) $where");

			}

		}

		$json = array('city'=>$city);
		$jcity = json_encode($json,true);
		echo $jcity;
		exit;
	}


		//行业类型数量统计
		public function gethylb(request $request){
			// 根据登录等级获取数量
			$dengji = Auth::guard('admin')->user()->dengji;
			$name1 = $request->name1;
			$name2 = $request->name2;


			$id = $request->id;
			$nid['id'] = $request->id;
			$area = DB::table('area')->where($nid)->first();

			$where = '';
			if(Auth::guard('admin')->user()->dengji == 4){
				$user_id = Auth::guard('admin')->user()->id;
				$where .= "and units.minjing = $user_id ";
			}
			if($request->name){
				$where .= "and units.name LIKE '%$request->name%' ";
			}
			if($request->type != null){
				$where .= "and units.type = $request->type ";
			}
			if($request->xingzhi != null){
				$where .= "and units.xingzhi = $request->xingzhi ";
			}
			if($request->is_del != null){
				$where .= "and units.is_del = $request->is_del ";
			}
			if($request->jibie != null){
				$where .= "and units.is_imp = $request->jibie ";
			}

			if ($id || $name2) {

			if ($id) {
				 if ($area->dengji == 1) {
					 $city = DB::select("SELECT SUM(units.type = 1) as 党政机关,SUM(units.type = 2) as 医疗单位, SUM(units.type = 3) as 高校,SUM(units.type = 4) as 中小学幼儿园, SUM(units.type = 5) as 商场超市,SUM(units.type = 6) as 金融保险证券, SUM(units.type = 7) as 加油站,SUM(units.type = 8) as 其他单位
 ,SUM(units.type = 9) as 公共交通,SUM(units.type = 10) as 供气企业,SUM(units.type = 11) as 供水企业,SUM(units.type = 15) as 物流寄递,SUM(units.type = 16) as 校园行业,SUM(units.type = 17) as 医院行业,SUM(units.type = 18) as 国家重点建设工程单位,SUM(units.type = 19) as 治安保卫重点的单位
							 ,SUM(units.type = 20) as 新闻单位,SUM(units.type = 21) as 国防科工,SUM(units.type = 22) as 教育单位,SUM(units.type = 23) as 科研单位,SUM(units.type = 25) as 商超金银珠宝,SUM(units.type = 26) as 电信网络运营,SUM(units.type = 27) as 大型物资储备单位,SUM(units.type = 28) as 大型体育场所
							 ,SUM(units.type = 29) as 大型文化场所,SUM(units.type = 30) as 大型能源动力设施,SUM(units.type = 31) as 博物馆,SUM(units.type = 32) as 档案馆,SUM(units.type = 33) as 重点文物保护单位,SUM(units.type = 34) as 涉及危险物品单位,SUM(units.type = 35) as 涉及传染性菌种、毒种的单位
 FROM units LEFT JOIN area on area.id = units.area WHERE area.cid = ? $where",[$id]);
					 //$res = DB::select("select a.name,count(b.id) as count from unit_type as a JOIN units as b on a.id = b.type WHERE b.city = $id group by a.name ORDER BY a.name");
				 }

				 if ($area->dengji == 2) {
					 $city = DB::select("SELECT SUM(units.type = 1) as 党政机关,SUM(units.type = 2) as 医疗单位, SUM(units.type = 3) as 高校,SUM(units.type = 4) as 中小学幼儿园, SUM(units.type = 5) as 商场超市,SUM(units.type = 6) as 金融保险证券, SUM(units.type = 7) as 加油站,SUM(units.type = 8) as 其他单位
 ,SUM(units.type = 9) as 公共交通,SUM(units.type = 10) as 供气企业,SUM(units.type = 11) as 供水企业,SUM(units.type = 15) as 物流寄递,SUM(units.type = 16) as 校园行业,SUM(units.type = 17) as 医院行业,SUM(units.type = 18) as 国家重点建设工程单位,SUM(units.type = 19) as 治安保卫重点的单位
							 ,SUM(units.type = 20) as 新闻单位,SUM(units.type = 21) as 国防科工,SUM(units.type = 22) as 教育单位,SUM(units.type = 23) as 科研单位,SUM(units.type = 25) as 商超金银珠宝,SUM(units.type = 26) as 电信网络运营,SUM(units.type = 27) as 大型物资储备单位,SUM(units.type = 28) as 大型体育场所
							 ,SUM(units.type = 29) as 大型文化场所,SUM(units.type = 30) as 大型能源动力设施,SUM(units.type = 31) as 博物馆,SUM(units.type = 32) as 档案馆,SUM(units.type = 33) as 重点文物保护单位,SUM(units.type = 34) as 涉及危险物品单位,SUM(units.type = 35) as 涉及传染性菌种、毒种的单位
 FROM units LEFT JOIN area on area.id = units.org_id WHERE area.cid = ? $where",[$id]);
					 //$res = DB::select("select a.name,count(b.id) as count from unit_type as a JOIN units as b on a.id = b.type WHERE b.area = $id group by a.name ORDER BY a.name");
	             }

	             if ($area->dengji == 3) {
					 $city = DB::select("SELECT SUM(units.type = 1) as 党政机关,SUM(units.type = 2) as 医疗单位, SUM(units.type = 3) as 高校,SUM(units.type = 4) as 中小学幼儿园, SUM(units.type = 5) as 商场超市,SUM(units.type = 6) as 金融保险证券, SUM(units.type = 7) as 加油站,SUM(units.type = 8) as 其他单位
 ,SUM(units.type = 9) as 公共交通,SUM(units.type = 10) as 供气企业,SUM(units.type = 11) as 供水企业,SUM(units.type = 15) as 物流寄递,SUM(units.type = 16) as 校园行业,SUM(units.type = 17) as 医院行业,SUM(units.type = 18) as 国家重点建设工程单位,SUM(units.type = 19) as 治安保卫重点的单位
							 ,SUM(units.type = 20) as 新闻单位,SUM(units.type = 21) as 国防科工,SUM(units.type = 22) as 教育单位,SUM(units.type = 23) as 科研单位,SUM(units.type = 25) as 商超金银珠宝,SUM(units.type = 26) as 电信网络运营,SUM(units.type = 27) as 大型物资储备单位,SUM(units.type = 28) as 大型体育场所
							 ,SUM(units.type = 29) as 大型文化场所,SUM(units.type = 30) as 大型能源动力设施,SUM(units.type = 31) as 博物馆,SUM(units.type = 32) as 档案馆,SUM(units.type = 33) as 重点文物保护单位,SUM(units.type = 34) as 涉及危险物品单位,SUM(units.type = 35) as 涉及传染性菌种、毒种的单位
 FROM units LEFT JOIN area on area.id = units.org_id WHERE area.id = ? $where",[$id]);
					 //$res = DB::select("select a.name,count(b.id) as count from unit_type as a JOIN units as b on a.id = b.type WHERE b.org_id = $id group by a.name ORDER BY a.name");
	             }

			}
				/*foreach ($res as $k=>$v){
					$city['0'][$v->name] = $v->count;
				}*/


			if ($name2) {


				if ($name1 == '湖北省') {
					$area = db::table('area')->where('name',$name2)->first();
					if ($area->dengji == 1)
					{
						$aid = $area->id;
						$city = DB::select("SELECT SUM(units.type = 1) as 党政机关,SUM(units.type = 2) as 医疗单位, SUM(units.type = 3) as 高校,SUM(units.type = 4) as 中小学幼儿园, SUM(units.type = 5) as 商场超市,SUM(units.type = 6) as 金融保险证券, SUM(units.type = 7) as 加油站,SUM(units.type = 8) as 其他单位
							 ,SUM(units.type = 9) as 公共交通,SUM(units.type = 10) as 供气企业,SUM(units.type = 11) as 供水企业,SUM(units.type = 15) as 物流寄递,SUM(units.type = 16) as 校园行业,SUM(units.type = 17) as 医院行业,SUM(units.type = 18) as 国家重点建设工程单位,SUM(units.type = 19) as 治安保卫重点的单位
							 ,SUM(units.type = 20) as 新闻单位,SUM(units.type = 21) as 国防科工,SUM(units.type = 22) as 教育单位,SUM(units.type = 23) as 科研单位,SUM(units.type = 25) as 商超金银珠宝,SUM(units.type = 26) as 电信网络运营,SUM(units.type = 27) as 大型物资储备单位,SUM(units.type = 28) as 大型体育场所
							 ,SUM(units.type = 29) as 大型文化场所,SUM(units.type = 30) as 大型能源动力设施,SUM(units.type = 31) as 博物馆,SUM(units.type = 32) as 档案馆,SUM(units.type = 33) as 重点文物保护单位,SUM(units.type = 34) as 涉及危险物品单位,SUM(units.type = 35) as 涉及传染性菌种、毒种的单位
							  FROM units LEFT JOIN area on area.id = units.area WHERE area.cid = ? $where",[$aid]);
					}
				}else{
					
					$b = db::table('area')->where('name',$name1)->first();
					$c['cid'] = $b->id;
					$c['name'] = $name2;
					$d = db::table('area')->where($c)->first();
					if ($d) {
						$aid = $d->id;
						$city = DB::select("SELECT SUM(units.type = 1) as 党政机关,SUM(units.type = 2) as 医疗单位, SUM(units.type = 3) as 高校,SUM(units.type = 4) as 中小学幼儿园, SUM(units.type = 5) as 商场超市,SUM(units.type = 6) as 金融保险证券, SUM(units.type = 7) as 加油站,SUM(units.type = 8) as 其他单位
 ,SUM(units.type = 9) as 公共交通,SUM(units.type = 10) as 供气企业,SUM(units.type = 11) as 供水企业,SUM(units.type = 15) as 物流寄递,SUM(units.type = 16) as 校园行业,SUM(units.type = 17) as 医院行业,SUM(units.type = 18) as 国家重点建设工程单位,SUM(units.type = 19) as 治安保卫重点的单位
							 ,SUM(units.type = 20) as 新闻单位,SUM(units.type = 21) as 国防科工,SUM(units.type = 22) as 教育单位,SUM(units.type = 23) as 科研单位,SUM(units.type = 25) as 商超金银珠宝,SUM(units.type = 26) as 电信网络运营,SUM(units.type = 27) as 大型物资储备单位,SUM(units.type = 28) as 大型体育场所
							 ,SUM(units.type = 29) as 大型文化场所,SUM(units.type = 30) as 大型能源动力设施,SUM(units.type = 31) as 博物馆,SUM(units.type = 32) as 档案馆,SUM(units.type = 33) as 重点文物保护单位,SUM(units.type = 34) as 涉及危险物品单位,SUM(units.type = 35) as 涉及传染性菌种、毒种的单位
 FROM units LEFT JOIN area on area.id = units.org_id WHERE area.cid = ? $where",[$aid]);
					}
	 			}
	 		}

			}else{

				if ($dengji == 1) {
				//获取全省下的级别统计数量
				    $city = DB::select("SELECT SUM(units.type = 1) as 党政机关,SUM(units.type = 2) as 医疗单位, SUM(units.type = 3) as 高校,SUM(units.type = 4) as 中小学幼儿园, SUM(units.type = 5) as 商场超市,SUM(units.type = 6) as 金融保险证券, SUM(units.type = 7) as 加油站,SUM(units.type = 8) as 其他单位
 ,SUM(units.type = 9) as 公共交通,SUM(units.type = 10) as 供气企业,SUM(units.type = 11) as 供水企业,SUM(units.type = 15) as 物流寄递,SUM(units.type = 16) as 校园行业,SUM(units.type = 17) as 医院行业,SUM(units.type = 18) as 国家重点建设工程单位,SUM(units.type = 19) as 治安保卫重点的单位
							 ,SUM(units.type = 20) as 新闻单位,SUM(units.type = 21) as 国防科工,SUM(units.type = 22) as 教育单位,SUM(units.type = 23) as 科研单位,SUM(units.type = 25) as 商超金银珠宝,SUM(units.type = 26) as 电信网络运营,SUM(units.type = 27) as 大型物资储备单位,SUM(units.type = 28) as 大型体育场所
							 ,SUM(units.type = 29) as 大型文化场所,SUM(units.type = 30) as 大型能源动力设施,SUM(units.type = 31) as 博物馆,SUM(units.type = 32) as 档案馆,SUM(units.type = 33) as 重点文物保护单位,SUM(units.type = 34) as 涉及危险物品单位,SUM(units.type = 35) as 涉及传染性菌种、毒种的单位
 FROM units WHERE units.id <> -1 $where");
					//$city = DB::select("select a.name,count(b.id) from unit_type as a JOIN units as b on a.id = b.type group by a.id ORDER BY a.id");
				}


				if ($dengji == 2) {
					$areaid = Auth::guard('admin')->user()->area_id;
					$city = DB::select(" SELECT SUM(units.type = 1) as 党政机关,SUM(units.type = 2) as 医疗单位, SUM(units.type = 3) as 高校,SUM(units.type = 4) as 中小学幼儿园, SUM(units.type = 5) as 商场超市,SUM(units.type = 6) as 金融保险证券, SUM(units.type = 7) as 加油站,SUM(units.type = 8) as 其他单位
  ,SUM(units.type = 9) as 公共交通,SUM(units.type = 10) as 供气企业,SUM(units.type = 11) as 供水企业,SUM(units.type = 15) as 物流寄递,SUM(units.type = 16) as 校园行业,SUM(units.type = 17) as 医院行业,SUM(units.type = 18) as 国家重点建设工程单位,SUM(units.type = 19) as 治安保卫重点的单位
							 ,SUM(units.type = 20) as 新闻单位,SUM(units.type = 21) as 国防科工,SUM(units.type = 22) as 教育单位,SUM(units.type = 23) as 科研单位,SUM(units.type = 25) as 商超金银珠宝,SUM(units.type = 26) as 电信网络运营,SUM(units.type = 27) as 大型物资储备单位,SUM(units.type = 28) as 大型体育场所
							 ,SUM(units.type = 29) as 大型文化场所,SUM(units.type = 30) as 大型能源动力设施,SUM(units.type = 31) as 博物馆,SUM(units.type = 32) as 档案馆,SUM(units.type = 33) as 重点文物保护单位,SUM(units.type = 34) as 涉及危险物品单位,SUM(units.type = 35) as 涉及传染性菌种、毒种的单位
  FROM units LEFT JOIN area on area.id = units.area WHERE area.id IN ($areaid) $where");
					//$city = DB::select("select a.name,count(b.id) from unit_type as a JOIN units as b on a.id = b.type WHERE b.city in ($areaid) OR b.area in ($areaid) or b.org_id in ($areaid) group by a.id ORDER BY a.id");
				}

				if ($dengji == 3) {
					$areaid = Auth::guard('admin')->user()->area_id;
					$city = DB::select(" SELECT SUM(units.type = 1) as 党政机关,SUM(units.type = 2) as 医疗单位, SUM(units.type = 3) as 高校,SUM(units.type = 4) as 中小学幼儿园, SUM(units.type = 5) as 商场超市,SUM(units.type = 6) as 金融保险证券, SUM(units.type = 7) as 加油站,SUM(units.type = 8) as 其他单位
  ,SUM(units.type = 9) as 公共交通,SUM(units.type = 10) as 供气企业,SUM(units.type = 11) as 供水企业,SUM(units.type = 15) as 物流寄递,SUM(units.type = 16) as 校园行业,SUM(units.type = 17) as 医院行业,SUM(units.type = 18) as 国家重点建设工程单位,SUM(units.type = 19) as 治安保卫重点的单位
							 ,SUM(units.type = 20) as 新闻单位,SUM(units.type = 21) as 国防科工,SUM(units.type = 22) as 教育单位,SUM(units.type = 23) as 科研单位,SUM(units.type = 25) as 商超金银珠宝,SUM(units.type = 26) as 电信网络运营,SUM(units.type = 27) as 大型物资储备单位,SUM(units.type = 28) as 大型体育场所
							 ,SUM(units.type = 29) as 大型文化场所,SUM(units.type = 30) as 大型能源动力设施,SUM(units.type = 31) as 博物馆,SUM(units.type = 32) as 档案馆,SUM(units.type = 33) as 重点文物保护单位,SUM(units.type = 34) as 涉及危险物品单位,SUM(units.type = 35) as 涉及传染性菌种、毒种的单位
  FROM units LEFT JOIN area on area.id = units.org_id WHERE area.id IN ($areaid) $where");
					//$city = DB::select("select a.name,count(b.id) from unit_type as a JOIN units as b on a.id = b.type WHERE b.city in ($areaid) OR b.area in ($areaid) or b.org_id in ($areaid) group by a.id ORDER BY a.id");
				}

				if ($dengji == 4) {
					$areaid = Auth::guard('admin')->user()->area_id;
					$city = DB::select(" SELECT SUM(units.type = 1) as 党政机关,SUM(units.type = 2) as 医疗单位, SUM(units.type = 3) as 高校,SUM(units.type = 4) as 中小学幼儿园, SUM(units.type = 5) as 商场超市,SUM(units.type = 6) as 金融保险证券, SUM(units.type = 7) as 加油站,SUM(units.type = 8) as 其他单位
  ,SUM(units.type = 9) as 公共交通,SUM(units.type = 10) as 供气企业,SUM(units.type = 11) as 供水企业,SUM(units.type = 15) as 物流寄递,SUM(units.type = 16) as 校园行业,SUM(units.type = 17) as 医院行业,SUM(units.type = 18) as 国家重点建设工程单位,SUM(units.type = 19) as 治安保卫重点的单位
							 ,SUM(units.type = 20) as 新闻单位,SUM(units.type = 21) as 国防科工,SUM(units.type = 22) as 教育单位,SUM(units.type = 23) as 科研单位,SUM(units.type = 25) as 商超金银珠宝,SUM(units.type = 26) as 电信网络运营,SUM(units.type = 27) as 大型物资储备单位,SUM(units.type = 28) as 大型体育场所
							 ,SUM(units.type = 29) as 大型文化场所,SUM(units.type = 30) as 大型能源动力设施,SUM(units.type = 31) as 博物馆,SUM(units.type = 32) as 档案馆,SUM(units.type = 33) as 重点文物保护单位,SUM(units.type = 34) as 涉及危险物品单位,SUM(units.type = 35) as 涉及传染性菌种、毒种的单位
  FROM units LEFT JOIN area on area.id = units.org_id WHERE area.id IN ($areaid) $where");
					//$city = DB::select("select a.name,count(b.id) from unit_type as a JOIN units as b on a.id = b.type WHERE b.city in ($areaid) OR b.area in ($areaid) or b.org_id in ($areaid) group by a.id ORDER BY a.id");
				}

			}

			 	 $json = array('city'=>$city);
				 $jcity = json_encode($json,true);
				 echo $jcity;
				 exit;
		}

		public function bags(request $request){

			// 根据登录等级获取数量
		$dengji = Auth::guard('admin')->user()->dengji;
		$name1 = $request->name1;
		$name2 = $request->name2;

			$id = $request->id;
			$nid['id'] = $request->id;
			$area = DB::table('area')->where($nid)->first();

			if ($id || $name2) {

		if ($id) {
				 if ($area->dengji == 1) {
					$city = DB::select("SELECT area.name,COUNT(*) as value FROM baoan_company LEFT JOIN area on area.id = baoan_company.area WHERE area.cid = ? GROUP BY area.name",[$id]);
				 }

				 if ($area->dengji == 2) {
	              		$city = DB::select("SELECT area.name,COUNT(*) as value FROM baoan_company LEFT JOIN area on area.id = baoan_company.org_id WHERE area.cid = ? GROUP BY area.name",[$id]);
	             }

	             if ($area->dengji == 3) {
	             	$city = DB::select("SELECT area.name,COUNT(*) as value FROM baoan_company LEFT JOIN area on area.id = baoan_company.org_id WHERE area.id = ? GROUP BY area.name",[$id]);
	             }

			}




		if ($name2) {


			if ($name1 == '湖北省') {
				$area = db::table('area')->where('name',$name2)->first();
				if ($area->dengji == 1)
				{
					$aid = $area->id;
					$city = DB::select("SELECT area.name,COUNT(*) as value FROM baoan_company LEFT JOIN area on area.id = baoan_company.area WHERE area.cid = ? GROUP BY area.name",[$aid]);
				}
			}else{
				
				$b = db::table('area')->where('name',$name1)->first();
				$c['cid'] = $b->id;
				$c['name'] = $name2;
				$d = db::table('area')->where($c)->first();
				if ($d) {
					$aid = $d->id;
					$city = DB::select("SELECT area.name,COUNT(*) as value FROM baoan_company LEFT JOIN area on area.id = baoan_company.org_id WHERE area.cid = ? GROUP BY area.name",[$aid]);
				}
 			}
 		}

		}else{

			if ($dengji == 1) {
			//获取全省下的市下的保安公司
			 $city = DB::select("SELECT area.name,COUNT(*) as value FROM baoan_company LEFT JOIN area on area.id = baoan_company.city WHERE area.cid = 0 GROUP BY area.name");

			
			}

			if ($dengji == 2) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT area.name,COUNT(*) as value FROM baoan_company LEFT JOIN area on area.id = baoan_company.area WHERE area.id IN ($areaid) and area.dengji = 2 GROUP BY area.name");
				
			}

			if ($dengji == 3) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT area.name,COUNT(*) as value FROM baoan_company LEFT JOIN area on area.id = baoan_company.org_id WHERE area.id IN ($areaid) and area.dengji = 3 GROUP BY area.name");
				
			}

			if ($dengji == 4) {
				$areaid = Auth::guard('admin')->user()->area_id;
				$city = DB::select(" SELECT area.name,COUNT(*) as value FROM baoan_company LEFT JOIN area on area.id = baoan_company.org_id WHERE area.id IN ($areaid) and area.dengji = 3 GROUP BY area.name");
			
			}

		}

		 	$json = array('city'=>$city);
			 $jcity = json_encode($json,true);
			 echo $jcity;
			 exit;


		}

		public function hygk(request $request){
				// 根据登录等级获取数量
				$dengji = Auth::guard('admin')->user()->dengji;
				$name1 = $request->name1;
				$name2 = $request->name2;

				$id = $request->id;
				

			if ($id || $name2) {

				if ($id) {

				$nid['id'] = $request->id;
				$area = DB::table('area')->where($nid)->first();
				$newarea = $area->name;
				
				 if ($area->dengji == 1) {
						$sy = DB::select("SELECT COUNT(*) as value FROM gasup  WHERE city = ?",[$newarea]);
					 	$kd = DB::select("SELECT COUNT(*) as value FROM kdxt  WHERE city =?",[$newarea]);
					 	$ky = DB::select("SELECT COUNT(*) as value FROM keyun  WHERE city = ?",[$newarea]);
					 	$ba = DB::select("SELECT COUNT(*) as value FROM bajg  WHERE city = ?",[$newarea]);

				 }

				 if ($area->dengji == 2) {
	              		$sy = DB::select("SELECT COUNT(*) as value FROM gasup  WHERE area = ? ",[$newarea]);
					 	$kd = DB::select("SELECT COUNT(*) as value FROM kdxt  WHERE area =?",[$newarea]);
					 	$ky = DB::select("SELECT COUNT(*) as value FROM keyun  WHERE area = ?",[$newarea]);
					 	$ba = DB::select("SELECT COUNT(*) as value FROM bajg  WHERE area = ?",[$newarea]);
	             }

	             if ($area->dengji == 3) {
	             		$sy = DB::select("SELECT COUNT(*) as value FROM gasup  WHERE org_id = ?",[$newarea]);
					 	$kd = DB::select("SELECT COUNT(*) as value FROM kdxt  WHERE org_id =?",[$newarea]);
					 	$ky = DB::select("SELECT COUNT(*) as value FROM keyun  WHERE org_id = ?",[$newarea]);
					 	$ba = DB::select("SELECT COUNT(*) as value FROM bajg  WHERE org_id = ?",[$newarea]);
	             }
	            }

			


			if ($name2) {


				if ($name1 == '湖北省') {
					$area = db::table('area')->where('name',$name2)->first();
					
					$sy = DB::select("SELECT COUNT(*) as value FROM gasup  WHERE city = ? ",[$name2]);
				 	$kd = DB::select("SELECT COUNT(*) as value FROM kdxt  WHERE city =?",[$name2]);
				 	$ky = DB::select("SELECT COUNT(*) as value FROM keyun  WHERE city = ?",[$name2]);
				 	$ba = DB::select("SELECT COUNT(*) as value FROM bajg  WHERE city = ?",[$name2]);



				}else{
					

					$sy = DB::select("SELECT COUNT(*) as value FROM gasup  WHERE area = ?",[$name2]);
				 	$kd = DB::select("SELECT COUNT(*) as value FROM kdxt  WHERE  area = ?",[$name2]);
				 	$ky = DB::select("SELECT COUNT(*) as value FROM keyun  WHERE area = ?",[$name2]);
				 	$ba = DB::select("SELECT COUNT(*) as value FROM bajg  WHERE  area = ?",[$name2]);


					// $b = db::table('area')->where('name',$name1)->first();
					// $c['cid'] = $b->id;
					// $c['name'] = $name2;
					// $d = db::table('area')->where($c)->first();
					// if ($d) {
					// 	$aid = $d->id;
					// 	$city = DB::select("SELECT area.name,COUNT(*) as value FROM baoan_company LEFT JOIN area on area.id = baoan_company.org_id WHERE area.cid = $aid GROUP BY area.name");
					// }
	 			}
	 		}

		}else{

				// if ($dengji == 1) {
				//获取散装油
				 	$sy = DB::select("SELECT COUNT(*) as value FROM gasup  WHERE province = '湖北省'");
				 	$kd = DB::select("SELECT COUNT(*) as value FROM kdxt  WHERE province = '湖北省'");
				 	$ky = DB::select("SELECT COUNT(*) as value FROM keyun  WHERE province = '湖北省'");
				 	$ba = DB::select("SELECT COUNT(*) as value FROM bajg  WHERE province = '湖北省'");

				
				// }

				// if ($dengji == 2) {
				// 	$areaid = Auth::guard('admin')->user()->area_id;
				// 	$city = DB::select(" SELECT area.name,COUNT(*) as value FROM baoan_company LEFT JOIN area on area.id = baoan_company.area WHERE area.id IN ($areaid) and area.dengji = 2 GROUP BY area.name");
					
				// }

				// if ($dengji == 3) {
				// 	$areaid = Auth::guard('admin')->user()->area_id;
				// 	$city = DB::select(" SELECT area.name,COUNT(*) as value FROM baoan_company LEFT JOIN area on area.id = baoan_company.org_id WHERE area.id IN ($areaid) and area.dengji = 3 GROUP BY area.name");
					
				// }

				// if ($dengji == 4) {
				// 	$areaid = Auth::guard('admin')->user()->area_id;
				// 	$city = DB::select(" SELECT area.name,COUNT(*) as value FROM baoan_company LEFT JOIN area on area.id = baoan_company.org_id WHERE area.id IN ($areaid) and area.dengji = 3 GROUP BY area.name");
				// }

			}

		 	 $json = array('sy'=>$sy,'kd'=>$kd,'ky'=>$ky,'ba'=>$ba);
			 $jcity = json_encode($json,true);
			 echo $jcity;
			 exit;


		}


	//index2数量统计
	public function getsltj(request $request){
		// 根据登录等级获取数量
		$dengji = Auth::guard('admin')->user()->dengji;
		$name1 = $request->name1;
		$name2 = $request->name2;

		$id = $request->id;
		$nid['id'] = $request->id;
		$area = DB::table('area')->where($nid)->first();

		$ryhc = '';
		$jqsb = '';
		$xsjb = '';
		if ($id || $name2) {
			if ($name2) {
				if ($name1 == '湖北省') {
					$area = db::table('area')->where('name',$name2)->first();
					if ($area->dengji == 1)
					{
						$aid = $area->id;
						$ryhc['total'] = db::table('rysh')->where('city',$aid)->count();
						$ryhc['cl'] = db::table('rysh')->where('city',$aid)->where('police_cl','1')->count();
						$jqsb['total'] = db::table('jqsb')->where('city',$aid)->count();
						$jqsb['cl'] = db::table('jqsb')->where('city',$aid)->where('police_cl','1')->count();
						$xsjb['total'] = db::table('xiansuo')->where('city',$aid)->count();
						$xsjb['cl'] = db::table('xiansuo')->where('city',$aid)->where('police_cl','1')->count();
					}
				}else{
					$b = db::table('area')->where('name',$name1)->first();
					$c['cid'] = $b->id;
					$c['name'] = $name2;
					$d = db::table('area')->where($c)->first();
					if ($d) {
						$aid = $d->id;
						$ryhc['total'] = db::table('rysh')->where('area',$aid)->count();
						$ryhc['cl'] = db::table('rysh')->where('area',$aid)->where('police_cl','1')->count();
						$jqsb['total'] = db::table('jqsb')->where('area',$aid)->count();
						$jqsb['cl'] = db::table('jqsb')->where('area',$aid)->where('police_cl','1')->count();
						$xsjb['total'] = db::table('xiansuo')->where('area',$aid)->count();
						$xsjb['cl'] = db::table('xiansuo')->where('area',$aid)->where('police_cl','1')->count();
					}
				}
			}
		}else{
			if ($dengji == 1) {
				//获取全省下的级别统计数量
				$ryhc['total'] = db::table('rysh')->count();
				$ryhc['cl'] = db::table('rysh')->where('police_cl','1')->count();
				$jqsb['total'] = db::table('jqsb')->count();
				$jqsb['cl'] = db::table('jqsb')->where('police_cl','1')->count();
				$xsjb['total'] = db::table('xiansuo')->count();
				$xsjb['cl'] = db::table('xiansuo')->where('police_cl','1')->count();
			}

			if ($dengji == 2) {
				$areaid = Auth::guard('admin')->user()->area_id;
			}

			if ($dengji == 3) {
				$areaid = Auth::guard('admin')->user()->area_id;

			}

			if ($dengji == 4) {
				$areaid = Auth::guard('admin')->user()->area_id;

			}

		}
		$json = array('ryhc'=>$ryhc,'jqsb'=>$jqsb,'xsjb'=>$xsjb);
		$jcity = json_encode($json,true);
		echo $jcity;
		exit;
	}

	public function getaqjctj(request $request){
		// 根据登录等级获取数量
		$dengji = Auth::guard('admin')->user()->dengji;
		$name1 = $request->name1;
		$name2 = $request->name2;

		$id = $request->id;
		$nid['id'] = $request->id;
		$area = DB::table('area')->where($nid)->first();

		$aqjc = '';
		if ($id || $name2) {
			if ($name2) {
				if ($name1 == '湖北省') {
					$area = db::table('area')->where('name',$name2)->first();
					if ($area->dengji == 1)
					{
						$aid = $area->id;
						$aqjc['total'] = db::table('jiancha')->where('city',$aid)->count();
						$aqjc['rc'] = db::table('jiancha')->where('city',$aid)->where('aqjc_type','1')->count();
						$aqjc['db'] = db::table('jiancha')->where('city',$aid)->where('aqjc_type','2')->count();
						$aqjc['zx'] = db::table('jiancha')->where('city',$aid)->where('aqjc_type','3')->count();
					}
				}else{
					$b = db::table('area')->where('name',$name1)->first();
					$c['cid'] = $b->id;
					$c['name'] = $name2;
					$d = db::table('area')->where($c)->first();
					if ($d) {
						$aid = $d->id;
						$aqjc['total'] = db::table('jiancha')->where('area',$aid)->count();
						$aqjc['rc'] = db::table('jiancha')->where('area',$aid)->where('aqjc_type','1')->count();
						$aqjc['db'] = db::table('jiancha')->where('area',$aid)->where('aqjc_type','2')->count();
						$aqjc['zx'] = db::table('jiancha')->where('area',$aid)->where('aqjc_type','3')->count();
					}
				}
			}
		}else{
			if ($dengji == 1) {
				//获取全省下的级别统计数量
				$aqjc['total'] = db::table('jiancha')->count();
				$aqjc['rc'] = db::table('jiancha')->where('aqjc_type','1')->count();
				$aqjc['db'] = db::table('jiancha')->where('aqjc_type','2')->count();
				$aqjc['zx'] = db::table('jiancha')->where('aqjc_type','3')->count();
			}

			if ($dengji == 2) {
				$areaid = Auth::guard('admin')->user()->area_id;
			}

			if ($dengji == 3) {
				$areaid = Auth::guard('admin')->user()->area_id;

			}

			if ($dengji == 4) {
				$areaid = Auth::guard('admin')->user()->area_id;

			}

		}
		$json = array('aqjc'=>$aqjc);
		$jcity = json_encode($json,true);
		echo $jcity;
		exit;
	}

	public function last_ryhc(request $request){
		// 根据登录等级获取数量
		$dengji = Auth::guard('admin')->user()->dengji;
		$name1 = $request->name1;
		$name2 = $request->name2;

		$id = $request->id;
		$nid['id'] = $request->id;
		$area = DB::table('area')->where($nid)->first();

		if ($id || $name2) {
			if ($name2) {
				if ($name1 == '湖北省') {
					$area = db::table('area')->where('name',$name2)->first();
					if ($area->dengji == 1)
					{
						$aid = $area->id;
						$re = db::table('rysh')->where('city',$aid)->limit(5)->orderBy('rysh_id','desc')->get();
					}
				}else{
					$b = db::table('area')->where('name',$name1)->first();
					$c['cid'] = $b->id;
					$c['name'] = $name2;
					$d = db::table('area')->where($c)->first();
					if ($d) {
						$aid = $d->id;
						$re = db::table('rysh')->where('area',$aid)->limit(5)->orderBy('rysh_id','desc')->get();
					}
				}
			}
		}else{
			if ($dengji == 1) {
				//获取全省下的级别统计数量
				$re = db::table('rysh')->limit(5)->orderBy('rysh_id','desc')->get();
			}

			if ($dengji == 2) {
				$areaid = Auth::guard('admin')->user()->area_id;
			}

			if ($dengji == 3) {
				$areaid = Auth::guard('admin')->user()->area_id;

			}

			if ($dengji == 4) {
				$areaid = Auth::guard('admin')->user()->area_id;

			}

		}
		foreach ($re as $k=>$v){
			if($v->police_cl == 1){
				$re[$k]->police_cl = '已处理';
			}else{
				$re[$k]->police_cl = '未处理';
			}
		}
		$json = array('re'=>$re);
		$jcity = json_encode($json,true);
		echo $jcity;
		exit;
	}

	public function last_jqsb(request $request){
		// 根据登录等级获取数量
		$dengji = Auth::guard('admin')->user()->dengji;
		$name1 = $request->name1;
		$name2 = $request->name2;

		$id = $request->id;
		$nid['id'] = $request->id;
		$area = DB::table('area')->where($nid)->first();

		if ($id || $name2) {
			if ($name2) {
				if ($name1 == '湖北省') {
					$area = db::table('area')->where('name',$name2)->first();
					if ($area->dengji == 1)
					{
						$aid = $area->id;
						$re = db::table('jqsb')->where('city',$aid)->limit(5)->orderBy('jq_id','desc')->get();
					}
				}else{
					$b = db::table('area')->where('name',$name1)->first();
					$c['cid'] = $b->id;
					$c['name'] = $name2;
					$d = db::table('area')->where($c)->first();
					if ($d) {
						$aid = $d->id;
						$re = db::table('jqsb')->where('area',$aid)->limit(5)->orderBy('jq_id','desc')->get();
					}
				}
			}
		}else{
			if ($dengji == 1) {
				//获取全省下的级别统计数量
				$re = db::table('jqsb')->limit(5)->orderBy('jq_id','desc')->get();
			}

			if ($dengji == 2) {
				$areaid = Auth::guard('admin')->user()->area_id;
			}

			if ($dengji == 3) {
				$areaid = Auth::guard('admin')->user()->area_id;

			}

			if ($dengji == 4) {
				$areaid = Auth::guard('admin')->user()->area_id;

			}

		}
		foreach ($re as $k=>$v){
			if($v->police_cl == 1){
				$re[$k]->police_cl = '已处理';
			}else{
				$re[$k]->police_cl = '未处理';
			}
		}
		$json = array('re'=>$re);
		$jcity = json_encode($json,true);
		echo $jcity;
		exit;
	}

	public function last_xsjb(request $request){
		// 根据登录等级获取数量
		$dengji = Auth::guard('admin')->user()->dengji;
		$name1 = $request->name1;
		$name2 = $request->name2;

		$id = $request->id;
		$nid['id'] = $request->id;
		$area = DB::table('area')->where($nid)->first();

		if ($id || $name2) {
			if ($name2) {
				if ($name1 == '湖北省') {
					$area = db::table('area')->where('name',$name2)->first();
					if ($area->dengji == 1)
					{
						$aid = $area->id;
						$re = db::table('xiansuo')->where('city',$aid)->limit(5)->orderBy('xs_id','desc')->get();
					}
				}else{
					$b = db::table('area')->where('name',$name1)->first();
					$c['cid'] = $b->id;
					$c['name'] = $name2;
					$d = db::table('area')->where($c)->first();
					if ($d) {
						$aid = $d->id;
						$re = db::table('xiansuo')->where('area',$aid)->limit(5)->orderBy('xs_id','desc')->get();
					}
				}
			}
		}else{
			if ($dengji == 1) {
				//获取全省下的级别统计数量
				$re = db::table('xiansuo')->limit(5)->orderBy('xs_id','desc')->get();
			}

			if ($dengji == 2) {
				$areaid = Auth::guard('admin')->user()->area_id;
			}

			if ($dengji == 3) {
				$areaid = Auth::guard('admin')->user()->area_id;

			}

			if ($dengji == 4) {
				$areaid = Auth::guard('admin')->user()->area_id;

			}

		}
		foreach ($re as $k=>$v){
			if($v->police_cl == 1){
				$re[$k]->police_cl = '已处理';
			}else{
				$re[$k]->police_cl = '未处理';
			}
		}
		$json = array('re'=>$re);
		$jcity = json_encode($json,true);
		echo $jcity;
		exit;
	}

	public function ryhc_detail(request $request){
		$re = db::table('rysh')->where('rysh_id',$request->id)->first();
		$re->dizhi = getValue($re->city,'area' ,'id' ,'name' ).getValue($re->area,'area' ,'id' ,'name' ).getValue($re->org_id,'area' ,'id' ,'name' );
		$json = array('re'=>$re);
		$jcity = json_encode($json,true);
		echo $jcity;
		exit;
	}

	public function jqsb_detail(request $request){
		$re = db::table('jqsb')->where('jq_id',$request->id)->first();
		if($re->jqlx == 1){
			$re->jqlx = '发生不安定事端';
		}elseif($re->jqlx == 2){
			$re->jqlx = '刑事案件';
		}elseif($re->jqlx == 3){
			$re->jqlx = '抓获违法犯罪嫌疑人';
		}elseif($re->jqlx == 4){
			$re->jqlx = '上报情报信息';
		}elseif($re->jqlx == 5){
			$re->jqlx = '火灾事故数';
		}elseif($re->jqlx == 6){
			$re->jqlx = '其它灾害事故数';
		}
		$re->dizhi = getValue($re->city,'area' ,'id' ,'name' ).getValue($re->area,'area' ,'id' ,'name' ).getValue($re->org_id,'area' ,'id' ,'name' );

		$json = array('re'=>$re);
		$jcity = json_encode($json,true);
		echo $jcity;
		exit;
	}

	public function xsjb_detail(request $request){
		$re = db::table('xiansuo')->where('xs_id',$request->id)->first();
		$re->dizhi = getValue($re->city,'area' ,'id' ,'name' ).getValue($re->area,'area' ,'id' ,'name' ).getValue($re->org_id,'area' ,'id' ,'name' );
		$json = array('re'=>$re);
		$jcity = json_encode($json,true);
		echo $jcity;
		exit;
	}





}